| Author |
Why Servlet is an interface not an abstract class
|
Kousik Majumder
Ranch Hand
Joined: Sep 30, 2007
Posts: 219
|
|
Hi All,
Can somebody explain me why javax.servlet.Servlet is an interface NOT an abstract class?
Please help.
|
Thanks in Advance,
Kousik
|
 |
Ravi C Kota
Ranch Hand
Joined: Jan 29, 2008
Posts: 61
|
|
Kousik Majumder wrote:Hi All,
Can somebody explain me why javax.servlet.Servlet is an interface NOT an abstract class?
Please help.
Servlet defines set of methods that can be invoked by the container. So defining the required functionalities upfront is a good approach. and if you notice, there is an abstract class called GenericServlet that implements Servlet Interface which in turn all other Servlets have been extended.
Is there any specific reason you think it should have been an abstract class rather than Servlet? As far as I understand, it is how they designed the framework. They wanted to define the functionalities first and then come up with implementation at a later point. So interface first and then implementation.
|
Thanks & Regards, Ravi C.Kota
SCJP 5.0, OCDJWS 5.0
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
Hey,
From the javadoc:
Defines methods that all servlets must implement.
It also states:
Sean
|
I love this place!
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3791
|
|
|
Which is quite a common approach - have an interface that defines the behaviour (for maximum flexibility), then have an abstract class implementing that interface to provide common behaviour. See java.util.List and java.util.AbstractList for another example.
|
 |
 |
|
|
subject: Why Servlet is an interface not an abstract class
|
|
|