Search code examples
model-view-controllerparadigms

Good examples of MVC?


Can anybody point to/give a very very correct example for the Model-View-Controller paradigm? I mean something really simple (like an inches to cm converter) implemented in some easy-to-understand language (VB.NET?) absolutely and exactly following MVC principles.


Solution

  • This one's pretty good: http://www.c2.com/cgi-bin/wiki?ModelViewController

    But really, MVC is very simple:

    • Model: Your DATA.
    • View: The thing that controls how your data is PRESENTED.
    • Controller: Sits between the data and the view, other data sources, and controls any changing of the data that needs to be done.

    This isn't to say that your view won't itself be built out of models, views, and controllers, but if you sort things according to these questions, things will usually stay pretty clean:

    1. Is it something the user interacts with, or that formats things for a user? It goes in the View.
    2. Is it just a representation of data, with little associated "smarts"? It's a model.
    3. Everything else goes in the controller.