0

In a MVC approach, who is responsible to create a right view for one specific model?

I have two classes C and D both subclass of A. My controller knows how to manage instances of A but it needs to instantiate differents views when objects are instances of C or D.

I have three possible approacs: I can move the complexity on the model, adding a method like getView but i think the model has to be more light as possible.

I can move the complexity on the controller, adding a switch based on model's class, but in this way the controller has to know all internals detail of the model.

I can move the complexity on the view, adding a metod like createViewForModel() but i have to put a switch inside this method...and is not a good thing.

Can someone share a link or a discussion about this topic? thanks

IgnazioC
  • 4,554
  • 4
  • 33
  • 46
  • If the layout of the view depends on the model, I'd do the custom initializer approach (move it onto the view). Otherwise controller. – CodaFi Mar 30 '14 at 12:11
  • are you talking about a Factory for View? And it's ok for you to have a switch inside that factory on Model Class? (or a custom `ModelType` property). – IgnazioC Mar 30 '14 at 12:51
  • If all you have are two specific instances, just make 2 separate initializers for the view, or dispense two different views, even, from the controller. – CodaFi Mar 30 '14 at 13:09

0 Answers0