Best practices for working with master data

What is the best design to use in an iPhone application that uses master data if you have several view controllers that make similar calls to master data?

I currently have an application in which there are several view controllers that perform similar functions, such as adding objects to an object, deleting an object, etc. I believe that there are several ways to handle this:

  • Each view controller has its own addItem: blah class. The bottom side is the result of some pasta copies between classes

  • Create a superclass that has basic data methods and inherits from this class. Override if necessary

  • Create a category so that all instances of view controllers have these methods without the need for a subclass

  • Create the syntax for the data manager that you can invoke. Perhaps this will be useful so that I can send requests to the queue and perform data management outside of each view controller. The disadvantage is that it seems like a bad idea at all

+4
source share
1 answer

CoreData and ViewControllers do not need to know about each other.

UIViewControllers are not traditional controllers in the MVC world. They are more closely related to views - and I prefer to create them with this in mind (most Apple code examples contain a lot of ModelController code - perhaps for the sake of simplicity).

I like to create ModelControllers and leave my ViewController to control my views, and I provide my ViewControllers with an instance of my ModelController.

My ModelController will manage my model, load, edit, delete, etc. I still expose Model classes for my ViewControllers, but Views NEVER leave ViewController. You will never see the view in ModelController.

The advantage of this is that if you later create an iPad application - your model and how it behaves is completely independent of your ViewControllers, so when you create several new UIViewControllers for your iPad application, you can connect your ModelControllers .

Your ModelController may have a parent class with your dual CRUD methods.

On the other hand....

A library called MagicalRecord https://github.com/magicalpanda/MagicalRecord adds an Active Record template to NSManagedObjects.

+4
source

Source: https://habr.com/ru/post/1391143/


All Articles