views:

88

answers:

2

I was having a look through the servlet-api.jar source code and found out (to my utter bewilderment) that javax.servlet.GenericServlet implements javax.servlet.ServletConfig.

Now, I don't boast to be an OOP scholar, but I do remember reading that although OOP provides the concept of inheritance, inheritance as a feature should be applied only when the child has an IS-A relationship with the parent.

"GenericServlet IS-A ServletConfig" does not sound right to me. Is any one aware of why was such a design decision taken ? (Apart from exposing ServletConfig's methods and attributes to GenericServlet) ?

A: 

implements and extends are different. implements means that GenericServlet must implement the interface defined in ServletConfig.

ie. a GenericServlet will have the ServletConfig interface, so GenericServlet will be configurable by anything that uses the ServletConfig interface to configure Servlets.

John Allen
What I would have expected was that GenericServlet be provided with an instance of ServletConfig, which means that "GenericServlet HAS-A ServletConfig". That sounds better for me.
divesh premdeep
A: 

Because ServletConfig is a poorly named interface. I would maybe rather call it ConfigServlet or ServletConfigurator.

BalusC