Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An ancestor/descendant question??

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am designing a service that handles ATP printing which is what takes place at airport kiosk ticket counters and at the gate. From the viewpoint of the client it will not care where or how a document is printed. It will simply call the print service and pass what is to be printed. There are three
types of printing and formats of printing. They are called CUTE, CUSS and Loyal printing. The meaning of each isn't important.

The print service will determine which type is to be printed from an application properties file and call the appropriate class. That;s where my question comes in. I can see having the same method in the service as the sub classes although these may or may not be descendents. They would all
have init methods as well as print methods. If the sub classes are descendents of the top level service can the ancestor contain class variables of each of the descendants such as in the following :

class PrintService
CUTEPrintService cuteps;
CUSSPrintService cussps;
LoyalPrintService lylps;

print()
{
if(CUTE) {
cuteps.print();
} else(CUSS) {
cussps.print();
} else(LOYAL) {
lylps.print();
}
}

Does this sound logical? Again, I ask this because I want the client to
not be concerned or care at all about where the print is going.

Thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a classic use for a Factory to me.

Asking the same method that decides which class to use be the same one that does the printing seems a potentially dangeroud confusion of resposibilities. Consider something maybe more like:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic