Rajesh Save wrote:
>
> I was just wondering ...
> Your are using a single instance of action class to process all the requests.
> Also to keep it thread safe, you don't use any instance variables. In that case
> why do we even need a single instance ? Why can't we just invoke the "static"
> method from the class. Something like Integer.ParseInt () ?
>
> Is it a bad practice to use classes this way ? or it has something to do with
> the fact that static methods are not overridden ?
>
One of the issues (if memory serves me right) is that you cannot declare static
methods in an interface. Therefore, you have to deal with each class individually,
instead of just casting to Action.
As a general O-O design principle, I personally dislike using static methods
(basically the Singleton pattern) in a case like this, because it limits my
flexibility in reusing the logic differently. What if I decided that I really did
want to create an instance per request so that I could use instance variables? Or
because I'm now moving to a JVM that has much lower instance creation overheads? I
cannot adapt to these kinds of changes quite as easily with Singletons.
This is also consistent with the design pattern you often see in the JDK's core
classes (such as java.util.ResourceBundle and java.util.Locale) -- there is a
static factory method to create new objects, but you do all the real work on an
instance.
> thanks,
>
> - Rajesh
>
Craig McClanahan
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets