Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Part II: Patterns > Decorator Pattern

Chapter 9. Decorator Pattern

In This Chapter

Understanding the Decorator Pattern 114

Building Reader Decorators 117

Building Visual and Commutative Decorators 128

Summary 136

The Decorator pattern enables you to apply new behavior to an object at runtime. Traditionally, many developers learn to add behavior by using inheritance rather than composition. This means that if you want to add a move() method to an existing Widget class, you’d extend Widget to define a new MovableWidget class. Or, if you want to redefine the move() method of MovableWidget so that it moves only until its fuel is used up, you could extend MovableWidget to define FuelableMovableWidget.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint