Dao core data template

I am starting to develop ios, and now I am studying the basic data. It was not clear to me when I was studying, many people managed the master data objects on the controller. For me, this is not MVC, since the main data is taken from the model layer.

So, I think it will be good to implement core data using the DAO pattern, but before I want to know if there is any kernel pattern or if some of them implement DAO using the kernel data?

+6
source share
2 answers

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.

+8
source

Are you looking for something like the Core Persistence Framework

This structure allows you to do the following:

DAOFactory *factory = [DAOFactory factory]; DAO *dao = [factory createRuntimeDAO:@"EntityName"]; NSArray *items = [dao findAll]; 

And a lot of interesting things.

+2
source

All Articles