Why MVC? Simply Explained

Disclaimer : I collected this from one support forum. Its not my original post.

MVC (Model – View – Controller) is one of those concepts that only starts to make sense when you’re dealing with larger applications and/or when working on the same application with several developers.

Compare it with tasks, if you’ve got 3 tasks that need to be done on a certain date, you won’t feel the need to have some kind of task organization, but if you have to deal with dozens of different tasks, with various due dates you’ll start using todo-lists. Then when you start working with a team of people and you need to prioritize and sequence tasks, you realize simple todo-lists won’t suffice and you’ll end up with applying SCRUM for instance (it obviously deals with more than task management, but it is one of the core parts of the methodology)

The same applies to MVC. It’s benefits are absolutely not restricted to large-scale, team-based development, but they become most obvious in such situations.

Let’s say you need to make a web application that loads some data in a xml file, lets the user do some operations on that data and saves the users edits in a SharedObject.
Fine. It’s a small application, you can develop it pretty fast and there’s no need to start thinking about using MVC or other patterns for structuring your components (not talking about UI components here, just cogs in the machine).
The application is a huge success and your client is extremely satisfied, they ask you to change the application because they’ll be setting up a back end with which the xml file can be manipulated by them, in fact no, they want to use a database instead of the file. And since it’s 2012 they definitely need an iphone app as well.
You’ll start working on the web application and since the deadline’s not just tight, but completely insane chances are you’ll be modifying it to reflect the use case changes, make a copy of the entire project to create the iphone app and again simply making the iOS required changes in that project directly.
Now repeat this five times. The client keeps on asking modifications. expansions etc. These can be UI related changes, but even complete backend architecture swaps, going from REST to SOAP for instance.
If you didn’t structure your project using MVC, you’ll be in a world of pain. No, you’ll be in a world of pain anyway, but had you used MVC from the start you’d notice that some things would’ve been less painful:

  • 95% of the code for the web application and the iphone app will be the same, but instead of saving the user data to a Shared Object or through a web service, you’d be using a local DB for instance. Due to the separation of concerns as promoted with MVC (and even more specifically with RL) you’d notice that the only thing different in the web app and the iphone app would’ve been a single service class. Without MVC chances are pretty high you’ll be making modifications in a bunch of classes.
  • The same applies to the UI for instance. Again, the heart of the application is the same, only the way it’s presented to the user is different. Due to separation of your app into the various tiers you’ll notice that changing the UI for the iphone app, will only have an impact on view classes and you’ll spent a tremendous amount of time less of searching through your code and finding out where to change what.
  • w/o MVC 95% of both apps would still be the same, but the differences would’ve been scattered in various files, here and there some lines, with MVC the differences will be in using different classes, ie the changes are more compact and overseeable.

All in all using MVC makes your code more structured and far more flexible to accomodate change in size, platform etc. etc.

Courtsey : creynders of Robotlegs Support

Advertisements

Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: