23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 15-2 C++ Code Fragments (continued)<br />

Decorator::Decorator( Component *myC)<br />

{ myComp= myC;<br />

}<br />

Decorator::prtTicket() { if<br />

(myComp != 0)<br />

myComp->prtTicket();<br />

}<br />

class Headerl : public Decorator<br />

{ public:<br />

void prtTicketO ;<br />

}<br />

Headerl::prtTicket () {<br />

// place printing header 1 code here<br />

Decorator: :prtTicketO ;<br />

}<br />

class Header2 : public Decorator<br />

{ public:<br />

void prtTicketO ;<br />

}<br />

Header2::prtTicket (} {<br />

// place printing header 2 code here<br />

Decorator::prtTicket 0 ;<br />

}<br />

class Footerl : public Decorator<br />

{ public:<br />

void prtTicket(};<br />

}<br />

Footerl::prtTicket (} {<br />

Decorator: :prtTicketO ;<br />

// place printing footer 1 code here<br />

}<br />

class Footer2 : public Decorator<br />

{ public:<br />

void prtTicketO;<br />

}<br />

Footer2::prtTicket (} {<br />

Decorator: :prtTicketO ;<br />

// place printing footer 2 code here<br />

}<br />

SalesOrder::prtTicket () {<br />

Chapter 15 • The Decorator Pattern 253<br />

(continued)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!