Today I realized that it is far easier to understand the intention behind MVC just by looking to a web product. Sites are usually made of a Database for Model, a Frontend for View, and a Backend for Controller.
Lately controller logic tends to live in various JavaScript frameworks (Dojo, AngularJS, EmberJS, etc.), lifting up weights from server side page controlling, rendering, routing, templating, etc. So they actually embody a whole MVC stack on their own. Anyway, the point is still the same.
While implementing a site (you can think of a simple MySQL-PHP-HTML triumph), you’ll never put any code about presentation details into the database, as you won’t put any piece of PHP into the frontend HTML, and so on. The so called term “inline PHP” means something that quiet discouraged, driven by the same intentions that an MVC application designed by.
You simply don’t want to depend the three parts on each other, so it is easy to create different presentation of the same data, split the frontend to desktop and mobile user interfaces for example. In practice, the three territory developed by different developers, and decoupling the parts let the teams work independently.
Developing mobile apps is (should be) just the same. Every app has a database – a Core Data stack for example – with its own rules (the model object graph, the store mechanism), has a frontend (the views, screens, panels, XIB definitions and so on), and a glue code between them (the controller objects playing the mediating role between).
To design a well structured system, you may think of your mobile app as it was a website. There are PHP codes that run on the server (the controller classes), and HTML/Javascript codes connected to the user at the client side (the view/view composite classes). The PHP code should have an interface to the underlying SQL (like a Core Data stack), but the frontend will never modify the data directly.
There are tons of readings out there about the advantages of the MVC (reusability, testability, debugability, maintainability, readability), I don’t want to sing it here. But the pattern should be as natural to the mobile developers, as it is to the web developers for ages.
The post Understanding MVC intentions appeared first on eppz!.