Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on GenericServlet

 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking at the api for GenericServlet.

Can aynone turn me onto the reason that, even though the class implements the ServletConfig interface, it has a separate method called getServletConfig()?

Why would a class need a method to getServletConfig() if it is an instanceof ServletConfig?
 
Paul Clapham
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it also implements Servlet, which has the getServletConfig() method, so it is forced to implement that method.
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I can see that. At the risk of seeming peevish, anyone have thoughts on why a class that's forced to supply a getter method for an interface would also implement that interface? I'm just trying to get a feel of the APIs structure and feeling lost.
 
Paul Clapham
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically GenericServlet implements Servlet because it wants to be a servlet. When I look at it, my peevishness arises from why it needs to implement ServletConfig. Smells like the bad kind of multiple inheritance to me. But this stuff was designed years ago. I bet if they were doing it now, GenericServlet wouldn't implement ServletConfig. It doesn't need to BE a ServletConfig if it already HAS a ServletConfig.

The way it is now, there's always a question of whether servlet.getServletConfig().x() returns the same thing as servlet.x() -- it appears that it always does, but why make a design where the question has to be asked?
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reality check. I'm glad someone else found the design to be strange.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic