klute wrote:
Interesting.. What about the following scenario:
say you have a base servlet that implements some interface for your app. it has validate() and forward() methods which encapsulates some logic used by all servlets in your app. doGet() and doPost() are different though. so, say my servlet A extends MyBaseServlet... here are my questions:
1) is it a good idea at all: design your servlet-based app by introducing a new hierarchy within a servlet api.
2) are there any thread safety issues that could be introduced by this since MyBaseServlet will be instantiated with every request as well? (note, validate() returns a boolean. no class level variables within any of the servlets (base or derived) are used)
I'm not sure I entirely understand what you're asking, but it sounds like you're saying all of your "implementation" servlets will be extending a single class "MyBaseServlet". If this is the case, then the answer to your second question is: there are no additional thread safety issues introduced beyond any thread safety issues that you would have to consider in the first place. Remember, the "implementation" servlets would be instances of "MyBaseServlet"; they are not instantiating a separate "MyBaseServlet" each time they are called.
To answer your first question, I wouldn't be the judge of what is good design and what isn't because I am a novice. But one thing I am coming to realize is that in OO design, you often want your subclasses to implement some interface defined by your parent class rather than give each subclass a handful of new methods because they are just "an extended version" of the parent class.
I used to think that subclassing was a great way to add new methods and functionality to my existing classes. I think in some cases this is fine. But usually this is indicative of the fact that the subclass is not really an instance of the parent class, but something else entirely, and perhaps in this case *composing* the parent class rather than *extending* it is the appropriate design to use. You really only want to use inheritance when you need to refer to the subclass as an instance of the parent class.
Otherwise you should probably just refactor out the functionality into helper class delegates.
Erik
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]