Hi there,

How should the controller's responsibilities be implemented in an MVC pattern?

I'd always thought that MVC looked like this:

Model - stores data/dispatches events

View - listens to Model for update event(s), then changes the view as per the updated data in the Model

Controller - listens to the view for changes, then updates the Model accordingly.

So the Model has no references to view/controller, View has a reference to the Model and Controller has references to Model and View.

However, I've seen a variation of the above where the view also has a reference to the Controller and calls handler methods on it directly, meaning the Controller ends up having a reference to the Model only i.e.

Model - stores data/dispatches events

View - listens to Model for update event(s), then changes the view as per the updated data in the Model. When the view is affected i.e. a button clicked, it calls handler methods on Controller i.e. controller.backButtonClicked()

Controller - When handler methods are called i.e. backButtonClicked(), it updates the Model accordingly.

Which is the correct use of the controller? The first or second example?

I get that the 2 examples above are doing pretty much the same thing and in a way the latter example may be more efficient as a listener has been removed, but it does mean that the view becomes dependent on the controller, when I'd have thought the purpose of the controller was to act as the inbetween for the Model/View.

Thoughts, anyone?