• Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet-mapping as a flag?  RSS feed

 
Ed Thompson
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working thru a design issue, and my gut says this is probably NOT a best practice, so I thot I would run it by some folks.

I have 3 servlets that are child classes of class L (A,B,C)

I need to have 3 servlets that are child classes of class C (X,Y,Z)

However the code in A=X, B=Y, C=Z. The only difference is parent class.

So I was thinking - combine L & C, have only 3 servlets A,B,C. Then use <servlet-mapping> to distinguish intent:

Map A to A and X to A - if called as A call the code merged from L, if called as X call code merged from C.

Doesn't smell right though. Is there a better pattern here?

Ed
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to help but I cannot understand what it is you are doing and what you want to do. Could you be more specific using real class names, perhapes the class code itself?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, the alphabet soup is a bit hard to follow... but in general switching on external implicit values such as the mapping is fragile and should be avoided. Switch on conrete explicit values such as scoped variables or request parameters. Or create subclasses for each mapping even if they don't do much but specify what's different.
 
Ed Thompson
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I redesigned using a factory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!