| You are here: | About>Computing & Technology>Delphi Programming> Coding Delphi Applications> OOP in Delphi> Free Online OOP Course> A Decorator - Delphi OOP Part 14 - Chapter 27 |
![]() | Delphi Programming |
Delphi OOP Course NavigationA DecoratorDelphi OOP Part 14 - Chapter 27Materials written by John Barrow. Modifications by Zarko Gajic
IntroductionIn chapters 11 and 13 we looked at ways of making the same object behave differently under different circumstances by changing the steps of an algorithm, the Template Method pattern, or by changing the algorithm itself, the Strategy pattern, or by changing the behaviour of an entire object or set of objects, the Factory patterns. These are all ways of changing the core operations of a class.In this chapter we look at situations where it is not necessary to change the core characteristics of an object at run time, but rather optionally to be able to add behaviour to the objects existing behaviour. In OO parlance we want to decorate an object and so well look at the Decorator pattern. Background to the Decorator Pattern exampleJoe's rather sleazy and cheesy Bioscope is a small-town cinema that shows full length features every Wednesday, Friday and Saturday. Joe's problem is that his attendance figures are falling steadily. In response he has introduced a Golden Oldies Club for senior citizens and a Silver Screen Loyalty Club for regular patrons. Members of these clubs receive tickets with additional customised annotations.Members of either or both clubs receive individually customised tickets. Golden Oldies get a special welcoming message while Silver Screeners (members of the loyalty programme) get a special message of appreciation. The Decorator PatternJoes Bioscope is a rather silly example, but it poses an interesting question. How does one change an object's behaviour in response to changing run time conditions? We have already looked at three approaches: the Template Method, where different subtypes implement the steps of a template in different ways, the Strategy, where a class can be associated with different algorithms or sets of rules, and the Factories, where entirely different objects are produced.Here we'll look at a fourth way of varying an object's run time behaviour, through use of the Decorator pattern. Whereas the previous patterns change the inner workings of an object or the object itself, the Decorator adds behaviour around a fixed core object. Because of this characteristic, a Decorator is sometimes also called a Wrapper. (This is rather confusing since Wrapper is also an alternative name for the Adapter pattern. We avoid using the word Wrapper in these notes.) Read the full chapter in the provided PDF... Chapter Contents
Chapter DownloadHere's the full text of the Delphi OOP part 14 available as PDF, along with the Delphi source code examples: This end the Delphi OOP Course.Delphi OOP Course Navigation |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


