I have a problem to understand how to properly download data from a database to my model object according to MVC architecture in my app.
Here is how the app looks like:
/ NavigationController -> ViewController -> ...
TabBarController - NavigationController -> ViewController -> ...
\ NavigationController -> ViewController -> ...
So TabBarController is initial controller with 3 tabs. Under each tab there is a chain of ViewControllers embedded in a NavigationController. Each View controlled by particular ViewController is displaying data from database. These data are updated quite often so I need to download them from database periodically.
Then I have a model object. In my app I have only this one model object so all ViewControllers have access to the same model object (I know each ViewController should have its own model object but I have reasons to do that in this way).
As I understand MVC, the communication should be like this:
- when a View must be updated, ViewController sends a request for data to a model object
- model object gets the data from a source
- when the data are updated, model object sends information to a ViewController
- ViewController updates data from a model object to a View
This should be OK. But I am not sure where should be placed a DatabaseController which connects to a database and sends requests to it. This should be separated controller and model object must have a reference to it because he needs to tell him that he needs update its data.
I have found some blog with information that the DatabaseController should be created inside the model object and separated from model object code using a category. My opinion is that this is bad idea because it breakes MVC architecture.
What do you think? What is the best solution for placing DatabaseController in the app? Should I put it into the object model or outside...
Aucun commentaire:
Enregistrer un commentaire