struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From St├ęphane Zuckerman <stephane.zucker...@gmail.com>
Subject Re: MVC Question
Date Wed, 03 Aug 2005 10:09:33 GMT
> I guess my question is: is the action form considered part of the model? If
> not, what?

I think the question's been asked (in a different way) a few days/weeks 
ago. Here's what Frank W. Zammetti said about it :

"
The Model is something, conceptually, outside of Struts.  Struts provides
nothing for dealing with the Model.

Imagine that you write some classes that know how to talk to your
database, know how to perform your business logic.  Further imagine that
these classes have a known set of methods (i.e., expose a known interface)
that can be called to form the application.

More specifically, imagine you have an application where you want to be
able to maintain a list of students and what classes they are taking in
school.  Without arguing about how best to actually architect this (i.e.,
let's forget about DTOs and DAOs and persistence layers and all that and
keep it simple), you might come up with something like this:

Class Student
-------------
Method: List listStudents()
  lists all students in the database
Method: void createStudent(String studentName, String ssn)
  Creates a user with a given SSN in the database
Method: Map getStudent(String studentName)
  Gets all the details for a given student from the database
Method: void addClass(String studentName, String className)
  Adds a class a given student is attending
Method: void deleteClass(String studentName, String className)
  Deletes a class a givent student is attending
Method: List listClasses(String studentName)
  Lists all the classes a given student is attending

 >From this you can create a webapp that allows you to list students, pick
one, see their details including what classes they are taking, and add and
remove classes.  Again, we're ignoring how you really should architect
this, I'm just trying to get the basic point across.

Also note that this is completely independant of the fact that you are
writing a webapp.  You can just as easily write a Swing-based client that
uses this class, or any other presentation technology.

Now, you have a single class that exposes a known interface that for all
intents and purposes represents your model.

Now, from your Struts Actions, you call these methods and render the
results as appropriate.  The method parameters like studentName and
className would probably be coming in as request parameters, so you just
instantiate your Student class and call the appropriate method, then take
the result and pass it to the view for display.  Struts itself doesn't
deal with the model for you.  How you get at these classes is also up to
you... could be a JNDI lookup, could be just included with your app, etc.
Struts leaves this to you entirely.

Hope that answers your question :)
"

-- 
St├ęphane Zuckerman

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message