This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes abstract HttpServlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "abstract HttpServlet?" Watch "abstract HttpServlet?" New topic
Author

abstract HttpServlet?

Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Hi,
Can anyone please explain me why the HttpServlet class defined in javax.servlet.http package is an abstract class. GenericServlet is an abstract class as it implements Servlet interface and thus inherits init(ServletConfig) method from it. Since it does not override init(Config) method and provide its body so it has to be an abstract class. GenericServlet class overloads init method and it also defines its body.

HttpServlet does not directly implement Servlet interface. All the methods which it inherits from GenericServlet is not abstract. So it must be a concrete class.

The only reason which I can think of is just to prevent direct instantiation of HttpServlet. Is there any other reason behind it.

Thanks & Regards

Naseem
[ July 08, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32481
    
214

Naseem,
It wouldn't make sense to directly instantiate a HttpServlet class as it wouldn't do anything.

One of the doXXX methods needs to be implemented to provide functionality. The reason the class isn't abstract is so you aren't forced to implement all the doXXX methods. Basically, it provides dummy implementations for you.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Thanks Jeanne.

I got your point.

Regards

Naseem
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: abstract HttpServlet?
 
It's not a secret anymore!