Re: Design Question for Model and View
Jason Cavett wrote:
One last question - a controller doesn't necessarily have to be a
separate class, does it? Can it be part of (from a class perspective
- not a logical one) the model or view - especially if it doesn't do a
whole lot?
You should be more precise in terminology. Let me rephrase your question; you
tell me if I did it wrong: "Does one need to implement the controller in a
separate component from the view or model?"
The "controller" is a concept. As such, it is distinct from the "model" and
"view" irrespective of implementation.
<http://en.wikipedia.org/wiki/Model-view-controller>
many of the links at the bottom of that page address your specific questions.
Google on "model-view-controller". There are many variants on the theme.
One, whose name escapes me and I just plain don't feel like doing all the
googling here, represents fractally more detailed controllers each with its
own mini- (micro-, pico-, femto-, ...) MVC loop.
Marty Hall [1] suggests implementing the controller as a distinct method in a
backing bean, if you're programming for JSF [2]. Other parts of the bean
implement the model, or part of it. I've done that; I've also implemented
controller functionality in a separate class, or even several separate
classes, using JSF.
Struts [3] uses a separate controller servlet that the application programmer
treats as a black box. Each Action class in Struts implements a method such
as execute() to handle the action for a screen. That method is the controller
for that screen. Or is it the logic? It's a floor wax /and/ a delicious
dessert topping!
Notes:
[1] <http://www.coreservlets.com/JSF-Tutorial/>
[2] <http://java.sun.com/javaee/5/docs/tutorial/doc/JSFIntro.html#wp114889>
<http://myfaces.apache.org/>
[3] <http://struts.apache.org/>
--
Lew