aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes An ancestor/descendant question?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "An ancestor/descendant question??" Watch "An ancestor/descendant question??" New topic
Author

An ancestor/descendant question??

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
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

Joined: Jan 07, 1999
Posts: 6920
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:



Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: An ancestor/descendant question??