This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract HttpServlet?

 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne.

I got your point.

Regards

Naseem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic