Maybe it is a dumb question but I would like to know when we have to or when it is recommanded to create new class. This is not really clear in my mind. For now, I’ve only one class per Controller and that’s it… All my code is in this class.
I think it could be better…
Regards
If you’re following the MVC pattern, for the most part your classes should be separated into one of those categories:
.xibfiles).For example, if you are building an RSS viewer according to this design pattern, you’d likely make the following classes:
UINavigationControllerwith a root view controller of theUITableViewControllerclass. Tapping on a table cell pushes anotherUIViewControllerresponsible for displaying an individual RSS item.UITableControllerhas a default view to display a list of items, the individual item likely needs custom logic to be displayed well. You might want to create a view class or.xibto present these. TheUIViewControlleris responsible for populating data on the view (setting values onIBOutletson the.xib, etc).As a general guideline, you should try to adhere to the single responsibility principle–every class should have a single responsibility, and it can perform its tasks more or less autonomously.
In this vein, controllers are responsible for handling the display of a single kind of view and for delegating messages from that view. Views are responsible for displaying data. Models are responsible for the singular purpose they were created for–an RSS item for mapping data from an RSS feed to an object, an RSS feed object for managing a group of RSS items (adding, removing, possibly fetching more via an
NSURLRequest).Note: Your question is a bit vague according to Stack Overflow guidelines, so that may be why it is being down-voted. Consider adding a specific example or description of the dilemma you’re facing.