Mvc – Who should register input listeners: the controller or the view? (MVC)

Architecturedesigndesign-patternsmvc

I'm using an (C++) SDK (Marmalade) and building a project around the MVC pattern. On my app, user input listeners may be registered on certain UI elements/widgets/etc providing a proper callback function (according to MVC should be a method of a controller, right?).

In this scenario, who should register these listeners:

  • The controller? (must have access to the view UI elements, less decoupling of control from presentation)
  • Or the view? (direct access to UI elements but must have a reference to the controller, isn't this incorrect in MVC?)

Between the two, I think the latter makes more sense and does better separation of concerns, but I'm afraid that I overlooked some problem with that design.

Thanks in advance.

Best Answer

It depends on the type of MVC you want. I suggest you try the Michael Feather's "humble dialog box", which is also called "model view presenter (MVP)", and probably what you are looking for.

In this variant, the view has a refererence to the controller, and the controller has a reference to an abstract interface of the view. So the view can provide methods for registering listeners, those methods are also available in the interface, and the controller will call these methods without having direct access to the UI.

Related Topic