Wednesday 18 April 2007

Decorator Pattern

BLOG 9

Decorator Pattern

The decorator pattern is a pattern used when u need to add more features to an object. For example in real life, a manufacturer may create a basic car, say a Mercedes Benz C-class. Adding more functionality to the car like added lights, navigation system, big rim, dust pad, CD changer with these actions u are decorating the more.

In GOF own words, a decorator pattern is “Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub classing for extending functionality” [GoF]

[GoF] GoF, elements of reusable Object Oriented Software e-book page 149

1 comment:

richie rich said...

Not a bad example but a bit short on the explanation of the pattern. The decorator pattern don't just add features it makes it dynamic, because you can use inheritance to add functions to an object. It also offers a pay-as-you-go approach to adding features to the object. This is a good pattern but it addes more object to your program and make debugging more difficult.