I have a few entities which are managed by custom NSManagedObject classes. They are being listed in different view controllers. Managed object subclasses have common abstract superclass which holds common attributes (let’s say its title as NSString and favorite as BOOL). I have view controller for favorites which lists, well.. all entities with favorite attribute as true. Since favorites have different classes – is it normal to derive (or get) the view controller class from appropriate subclass of abstract superclass of those managed objects? Am I breaking the MVC here?
Update
Some clarification for sergio: Let’s say I have abstract superclass Animal and subclasses like Cat, Dog. Instances of these represent individual animals (like animals with names). Then I have CatsViewController and DogsViewController. They list instances of appropriate Animal subclass. I also have CatDetailsViewController and DogDetailsViewController which represent single instances of managed objects. Then I have FavoritesViewController which lists both – cats & dogs in a table. Upon a tap of a row I want to take the user to appropriate CatDetail or DogDetail view controller. This where the question comes – can I derive/get the class of view controller from the instance of managed object. I am also open to other options of realizing this.
EDIT (after comment):
This is perfectly MVC compliant, IMO. Your
FavoritesViewControlleris in charge of telling which object you are dealing with and invoking the right specific controller (CatDetail or DogDetail view controller). It still embeds knowledge about the business logic of your app and model and views are properly separated from it. You see, in the end, betweenFavoritesViewControllerandDogsViewController/CatsViewControllerthere is not much difference; the only difference is thatFavoritesViewControllerknows about two types of data instead on only one.OLD ANSWER:
I am not sure I understand fully your scenario, but from what I understand, I would say that you are maybe breaking a little the principle of encapsulation; then, it comes down to how you are doing it, i.e., if you use a factory, or how do you instantiate your specific controller base on model information.
As to the MVC, I think you are not breaking it specifically. As long as a “controller” is in charge of creating your specific controller classes, you are playing within its boundaries.
Well, take this with a grain of salt, since I have only a very partial understanding of what you are doing. In any case, hope it helps.