Kousik Majumder wrote:Hi All,
Can somebody explain me why javax.servlet.Servlet is an interface NOT an abstract class?
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.
From the javadoc:
It also states:
Defines methods that all servlets must implement.
To implement this interface, you can write a generic servlet that extends javax.servlet.GenericServlet or an HTTP servlet that extends javax.servlet.http.HttpServlet.