Where can I find clear examples of MVC?

45,142

Solution 1

IMO, the best examples are with code and/or starter kits.

Rob Conery has a great number of posts that explain how to to create an MVC site with ASP.NET MVC. Each one of these has a video tutorial which runs through the blog post discussion.

The official ASP.NET MVC site also has some video posts, starter kits (here, here and here) and extra sauce to help.

IMO, MVC is the way to go for Web Sites. Without spewing all the jargon and marketing speak, it really breaks down your code into nice, separate and defined sections. Each of these sections can also be tested .. which really helps protect the development process because you have peace of mind knowing that touching one part of the system doesn't break another (because the tests all pass after your latest change).

Other blogs which you should check out:

Solution 2

Assuming you mean MVC for the web you'd be hard pressed to find anything more concise than the following 60 lines of code:

http://code.google.com/p/barebonesmvc-php/

In particular note the sendResponse "template method", which in turn is essentially comprised of the following 2 method calls:

applyRequestToModel

applyModelToView

Solution 3

One of the heighest rated that I've seen is the the Learn MVC in 7 days post. Of course, as good as it is, it still pales in comparison to a book like Pro ASP.NET MVC 4

Solution 4

I have done this every which way for various projects. From coding everything for an application in one great big PHP script (OK it started as a small PHP script which just grew). To using the latest greatest Spring/Freemarker framework where my 5O lines of java code were lost in a sea of XML and template coding.

You can do MVC without a framework, and, in php this is probably the simplest way. If all your navigation code is in a single script with only navigation logic then you are doing MVC!

For anything other than a QDP (Quick Dirty Page) I would recommend using some sort of MVC. Just imagine what you would need to do if the business said "can I have a French language version" or "great program but I want to store the data in xxxxx database".

Solution 5

there are some flavours of mvc: http://en.wikipedia.org/wiki/Presentation-abstraction-control, http://en.wikipedia.org/wiki/Model_View_Presenter.

also see: http://c2.com/cgi/wiki/like?ModelModelViewController

related question: Examples of Hierarchical-Model-View-Controller (HMVC)?

Share:
45,142

Related videos on Youtube

Tom
Author by

Tom

[email protected]

Updated on March 19, 2020

Comments

  • Tom
    Tom about 4 years

    I've read a couple of things about MVCs but I still don't understand when they should be used and when they shouldn't be used. I am looking for clear examples that say things like "if you're developing this then you should use MVC, like this" and "if you're developing this, you shouldn't use MVC." Most of the examples I've seen rely on complex frameworks which have already implemented everything and you have to learn the framework and use it a lot to understand what's really happening. To many programmers, phrasings such as "UI business logic" sound like marketing terms — for example, the words "Instead the View binds directly to a Presentation Model" are used in this post.

    I am aware of the dangers that may lurk in the shadows as MVC is a concept and everyone feels like they know it best, yet nobody really knows exactly how to use it because there may be a lot of variables involved and everyone is allowed to have a different perspective on how to dissect a project into the Model, the View and the Controller. There is a lot of theory out there but very few clear examples. What I'm looking for are not "the best" ways of doing it so this should not be considered as subjective; I'm looking for different simple implementations that would allow me to decide on my own which are the best approaches.

    Succinctly: What are good on-line resources that present pro and con arguments to using MVC in various situations and provide clear examples to help the reader understand the concept?