Hi all, I have this doubt for a long time... hope anyone can enlight me.
Suppose I have 3 classes in my model.
abstract class Document {}
class Letter extends Document {}
class Email extends Document {}
and a service class with a method that returns a Document (either a Letter or Email).
class MyService {
public Document getDoc(){...}
}
So in my controller I want to display the Document returned by MyService, and I want it to be displayed using a view for the Email and other for the Letter. How could a controller know which document view invoke? the letterView or the emailView?.
Often I make an if statement on the controller to check the type of the Document received by the service tier... however I dont think it is the best approach from the OOP point of view, also if I implement a few boolean methods Document.isLetter(), Document.isEmail() the solution is, in essence, the same.
Another thing is to delegate the view selection to the Document somehow. something like:
class MyController {
public View handleSomething() {
Document document = myService.getDocument();
return document.getView();
}
}
But, omg, why my model objects must know anything about the view?
Any toughts are appreciated :)