开发者

Why should javax.servlet.GenericServlet implement javax.servlet.ServletConfig?

开发者 https://www.devze.com 2022-12-13 10:51 出处:网络
I was having a look through the servlet-api.jar source co开发者_运维技巧de and found out (to my utter bewilderment) that javax.servlet.GenericServlet implements javax.servlet.ServletConfig.

I was having a look through the servlet-api.jar source co开发者_运维技巧de 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) ?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消