class SalesTicket : public Component { public: void prtTicket(); } SalesTicket::prtTicket() { // sales ticket printing code here } class Decorator : public Component { public: virtual void prtTicket(); Decorator( Component *myC); private: Component *myComp; } Decorator::Decorator( Component *myC) { myComp= myC; } void Decorator::prtTicket() { myComp->prtTicket(); } class Header1 : public Decorator { public: Header1( Component *myC); void prtTicket(); } Header1::Header1 (Component *myC) : Decorator(myC) { } void Header1::prtTicket () { // place printing header 1 code here Decorator::prtTicket(); } class Header2 : public Decorator { public: Header2( Component *myC); void prtTicket(); } Header2::Header2 (Component *myC) : Decorator(myC) { } void Header2::prtTicket () { // place printing header 2 code here Decorator::prtTicket(); } class Footer1 : public Decorator { public: Footer1( Component *myC); void prtTicket(); } Footer1::Footer1 (Component *myC) : Decorator(myC) { } void Footer1::prtTicket () { Decorator::prtTicket(); // place printing footer 1 code here } class Footer2 : public Decorator { public: Footer2( Component *myC); void prtTicket(); } Footer2::Footer2 (Component *myC) : Decorator(myC) { } void Footer2::prtTicket () { Decorator::prtTicket(); // place printing footer 2 code here } void SalesOrder::prtTicket () { Component *myST; // Get chain of Decorators and SalesTicket built by // another object that knows the rules to use. // This may be done in constructor instead of // each time this is called. myST= Configuration.getSalesTicket() // Print Ticket with headers and footers as needed myST->prtTicket(); } |
3.129.9.48