Mvc – Where do the parser and service objects fit in MVC

iosmvc

Do NSURLConnection service objects and XML/JSON parser objects fall within the controller layer or the model layer? Why?

Is it OK to have business logic in the controller? Or should it be in the model layer only?

Can the model layer be represented by NSArray/NSDictionary objects or should it be strictly structured with custom objects to comply with the MVC pattern, given that my app doesn't require persistent storage.

Best Answer

All your business rules (and application) should be in the model layer of your application. The controller should just be collecting (from models to views) and sending (from URL requests to models) the data.

Your models can be composed in two layers, the business logic (and application) and your data access layer. Your data access layer execute queries (SQL, NoSQL, Web Service or even text files).

Your models should not be "aware" of the type of storage you are using. This way, you can change and combine different data access mecanism (your users are in a database and the rest of the data comes from a web service for example).

To cleanly integrate your data access layer in your models you should rely on dependency injection

Related Topic