MVC implementation question using Swing 2004-05-19 - By Martin C?
Back Hi,
A question on how to implement the MVC design pattern.
I'm currently building a personal application using Java with Swing. I would eventually like to port it on JSP/Servlet as well.
I always imagined as the Model being completely separated from the Controller and the View. The model classes shouldn't know about the View or the Controller. However, I see the model classes should extend the Observable class and enable the other 2 to be notified on data changes.
Now, if I have a main class that is used to execute the program, I would see the implementation of the MVC in that class as:
Model rootModel = new Model();
Controller rootController = new Controller(rootModel); String language = "en"; View rootView = new View(rootController, rootModel, language);
(Please, correct it if that's incorrect.)
My problem comes from the fact that the main 'root' model class is taking arguments that is obtained from one of the UI. More specifically, my 'root' model class is User, which logically should always take a firstname and lastname. To me, it doesn't really make sense to have a user with a blank firstname/lastname. However, to get this information, I need to display the login window.
Should I create a 'higher' root model class that wouldn't take any parameters and create the User object only once I got the information? Something similar to the "session" when you're coding using JSP and servlet; like "MyAppSession"?
Or should I break all these 'groups' into multiple classes visible by the main class? I'm kind of reluctant to do that. That would mean that there would be multiple instanciation of view classes in the main class, etc.
Or is there any options I'm leaving out? Am I taking the right approach towards the MVC design pattern? Or if you could suggest a different approach to implement the whole thing...
Thanks for your help, Martin
__ ____ ____ ____ ____ ____ ______ Do you Yahoo!? Yahoo! Domains ? Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer
==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
|
|