Many should know that MVC has been around for at least 30 years if not longer. Traditionally MVC was used to support apps that only ran on one device type i.e. the PC. In that time the POCO/POJO was the Model, the UI was the View and the code-behind class was the Controller.
However apps today may span multiple device types: PC, phone, tablet, watch, tv, game box. This is why the new level of abstraction is needed. As @rperes mentioned, it is necessary to separate your view business logic out of your UIViewController because that business logic may need to be re-used across multiple device types that may use different UI frameworks. In addition it allows your view business logic to be tested via unit tests.
In order to support multiple device types, it is necessary to understand that UIViewControllers (which are equivalent to code-behind classes) no longer fall under the âControllerâ layer but are actually now part of the âViewâ layer in MVC . In the multiple device types scenario, your new âControllerâ class should be clueless to what UI framework it is being coupled with.
It is this new level of abstraction that allows your business logic to be re-used across device types. Please be aware that âview business logicâ is completely different than âUI framework logicâ.
An example of âview business logicâ is something like this: to edit an order, the user should have a security level of administrator. That business rule would be true regardless of whether the app was being executed on a phone, pc or iPad.
UI framework logic would be something like: âWhen the user edits an order the screen should do a flip animation and present the user with the order detailsâ. The classes and frameworks used to accomplish the flip animation may vary across device types.
Examples such as this is why it is necessary for an extra layer of abstraction to exist between the business view logic and the UI framework logic. You shouldnât have to duplicate the business logic across device types and thats why the new level of abstraction is needed.
Also, should models have logic? This is one of those things that devs go back and forth on. Models that only have properties are known as âanemicâ models and many swear by this approach. I kind of take a middle of the road approach. I usually have a library that contains anemic models and then attach small utility type methods to them via extensions (emphasis on the phrase âutility type methodsâ). You shouldnât put major business logic within your models. You also shouldnât put data retrieval logic within your models. All of that is a big no-no.
The methods that should be attached to models should be very type specific and should be logic that will be needed across multiple controllers. A quick example is something like letâs say an order number looks like this: â17B-234-X33â.
And say you need a method to retrieve the 3rd and 9th character which is always a letter and signifies customer type - that would go in your Order model. Now letâs say you want to retrieve all orders for a particular date - that WOULD NOT go in your Order model. It would go into your data service. At least thatâs how I do it