Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

It depends on the form of MVC you want. I suggest you try the Michael Feather's "humble dialog box", which is also called "model view presenter (MVP)", but 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 can call these methods without having direct access to the UI.

share|improve this answer
That "humble dialog box" is a great example. Reading this, I think that I should go more for a MVP architecture than a MVC one. Thanks. – pedrosanta May 20 '12 at 15:47

If I understand the question correctly, and I kind of doubt I do, the answer is none of the above. Registering event listeners with their sources should generally be the responsibility of a third part, a builder of some sort that constructs the system and starts it off.

share|improve this answer
Think about your answer in a scenario where listeners have to be dynamically registered and unregistered, not just at the time the system is initialized. – Doc Brown May 20 '12 at 15:23
Yes, that's precisely my scenario. :) – pedrosanta May 20 '12 at 15:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.