Daniel Lopez wrote:

> Hi Drew,
>
> What you ask for shouldn't be too difficult to implement. If I had to do
> it, I'd use reflection, as you mentioned, and I'd just add a new field
> in configuration file to allow the user to specify the name of the
> method to be called. However, if you want the methods to be executed
> using one instance, then you should also add something to identify the
> instance you want to use for every operation. If you wanted to call
> methods that have parameters things could get much more cumbersome.
>

It isn't actually that bad.  The Java Reflection API lets you dynamically select a
method name, and set up a list of arguments in an array.  You do, however, have to
know how many arguments to send (and what types they are), which leads to the next
comment.

>
> On the other hand... do you think it is really necessary to call
> different methods in the same class?. If you store the bean in the
> session( or in servlet context) and each operations is a small class
> that gets the parameters and calls the appropriate method from that
> shared bean, things get easier and, IMHO, more cleanly separated.
> As you pointed out, this Bean that you keep between calls inside the
> same user session, fits pretty much into the definition of a session
> EJB.
>
> As I conclusion, I'll just say that I opted for the command pattern
> because it keeps the controller servlet, and the configuration file,
> simpler and because I prefer to have a set of simple classes that
> perform each one a simple operation than one, or more classes, that
> implement everything. I find this arrangement easier to understand,
> debug, and easier to work with, when you develop in group. But that's a
> matter of taste.
>

I chose exactly the same approach (all my commands are independent Action classes
that implement an Action.perform(HttpServletRequest req, HttpServletResponse res)
method.  I made this choice for the same reasons that Dan articulated (boy, we
must be pretty smart :-).  To avoid class creation overhead, I cache an instance
of each Action class the first time it is used, and just re-use the same instance
over and over again for subsequent requests to the same command.  Now, I can code
my action classes totally independently of each other, and be pretty confident
there's no side effects from multithreading or other factors.

>
> Just my 2c,
> Dan

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to