hi;
without diving into the details of what you wrote...
swing comes with some built in MVC classes.
for example: a JTable object (view) will have a TableModel object(model) and
various listeners (implements by a controller). so try not to write anything
you don't have to.
if you are considering porting your application to a web application, try to
prepare use cases that will fit both types of application (swing apps tend
to have more versatile than web apps) and built the corresponding business
delegates so that both your applications will reuse the same business
scenarios.
there is no need to come up with a new MVC design that will fit both type of
apps cause you will surely end up will an incomplete implementation of
things that already exist (struts(web),waf(web),swing built in mvc
components client app)).
thanks.
-----Original Message-----
From: cotem00@(protected)]
Sent: Thursday, May 20, 2004 1:04 AM
To: J2EEPATTERNS-INTEREST@(protected)
Subject: MVC implementation question using Swing
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)
====================================================================
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)