23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 15<br />

The Decorator Pattern<br />

Overview<br />

This chapter continues the e-tailing case study introduced in Chap- In this chapter<br />

ter 14, "The Strategy Pattern."<br />

In this chapter,<br />

• I describe a new requirement for the case study: Add header<br />

and footer information to the printed sales ticket.<br />

• I show how the Decorator pattern handles the requirement<br />

flexibly.<br />

• I discuss how the Decorator pattern can be used to handle<br />

input/output (especially Java I/O).<br />

• I describe the key features of the Decorator pattern.<br />

• I describe some of my experience using the Decorator pattern<br />

in practice.<br />

A Little More Detail<br />

Figure 14-2 showed the basic structure of the case study. Figure Expanding the<br />

15-1 shows this structure in more detail. Here, I show that the diagram<br />

SalesOrder object uses a SalesTicket object to print a sales ticket.<br />

As you saw in Chapter 14, SalesOrder uses a CalcTax object to<br />

calculate the tax on the order. To implement the printing function,<br />

SalesOrder calls the SalesTicket object, requesting that it print<br />

the ticket. This is a fine, reasonably modular design.<br />

241

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

Saved successfully!

Ooh no, something went wrong!