Reputation: 11462
I have read several resources so far about MVC design pattern for iPhone application development. However I have one question related Model part of MVC in iPhone development context.
Firstly, I would like to say what I think of MVC,
Model : is related to a data which we have regarding our application's objects. Example : Application of a Train simulator than, Each train on simulation will be having it'e own attributes and that will be saved inside Train model.
Controller : is something which controls UI updates. It keeps a reference to Train model and checks for any changes in model, If there is than change the View of that particular train. And it keeps checking for any UI input so it can change data inside Model.
View : This is fairly obvious View is all about UIView, What we see on screen.
Now, Question is...
Does Model has to be persistent to be considered as a Model? or I can have a Class which has variables without any persistency. Would that be considered as Model as well, Or Model must be stored somewhere like in CoreData or .Txt file etc....
Thanks for any input!
Upvotes: 9
Views: 1953
Reputation: 9162
No, a model doesn't have to be persistent.
In theory a good way to start your project would be to use a non-persistent model for simplicity. Then when you change your model to become persistent, you should not have to make any changes to your view or controller, since you will design the interface to be unaware of the details of the model.
In practice that's not a great idea on iPhone if you're planning to use Core Data for your model when you make it persistent. Core Data requires you to design your classes in a little bit of a different way. Even though you shouldn't have to make many changes to your view and controller code when you change your model, you will have to make a lot of code changes to your model. If you know you will be using Core Data, better to start right off with it.
Upvotes: 3
Reputation: 198556
No, the idea behind MVC does not actually relate to databases, although that is usual. The model simply should capture all the business logic. If you are building a calculator, view is the display and the buttons, model is the part of code that knows how to add and subtract, and controller is the one that connects the two. No persistence involved.
Upvotes: 3
Reputation: 3194
Does Model has to be persistent to be considered as a Model?
It may vary or transform as long as your controller can support it.
Model must be stored somewhere like in CoreData or .Txt file
Not at all.
You can use any Model if applicable. Model is just another abstraction of your actual logic/database/network access/blablabla...
Upvotes: 7