Sunday, May 16, 2010

Model View Controller

Straight to the point: in a MVC architecture, do Model and View need to communicate directly, or all the communications should be mediated by the Controller? There are two schools of thought regarding this topic, and the question often generates little funny religion wars.
The best answer to this question which I have ever found is in the Cocoa Design Patterns document, available on the Apple dev center website (by the way, the document is a recommended reading regarding design patterns in general, whatever the language, platform or technology you use).

To sum up, the document describes both models, named "traditional model" (in which there is direct communication between model and view) and the "Cocoa model", in which the Controller always mediates between View and Model.

Here is the "Traditional" MVC model:

Here is the "Cocoa" MVC model:


One of the main arguments in defence of the second architecture is that it theoretically improves the reusability of View and Model, because they are totally decoupled.
Read Cocoa Design Patterns for a thorough discussion!

No comments:

Post a Comment