Indeed, it is correct to avoid using data retrieval methods in the controller. In this way, the philosophy behind the MVC design pattern is respected: the controller should simply name the high-level βglueβ and, therefore, act as a document describing how the view interacts with the model.
Regarding permanent facilities, there are two main approaches to this:
- Use ActiveRecord Template
- Use the data access object template.
A Data Access Object (DAO) is an interface dedicated to storing a model / domain object in a data source.
The ActiveRecord template places persistence methods on the model object itself, while the DAO defines a discrete interface. The advantage of the DAO template:
It is easy to define a different persistence style, for example, the transition from the database to the cloud, without changing the interface and, therefore, for other classes.
Save problems are stored in the module away from the main problems associated with the model object.
The advantage of the ActiveRecord template is simplicity.
ActiveRecord for CoreData strong>
Currently, the ActiveRecord template looks much more popular among Objective-C developers. The following project provides ActiveRecord for CoreData: https://github.com/magicalpanda/MagicalRecord
DAO for CoreData strong>
I am not familiar with the widely used library that provides the DAO template for CoreData. However, it could be easily applied without the help of a library:
- Define all your data methods for a specific object - findByName, save, delete, etc. in the protocol.
- Implement the protocol by calling the appropriate CoreData methods.
NB: An example project for the Typhoon framework will soon contain some examples of applying the DAO pattern with CoreData.
source share