Friday, April 20, 2007

Decorator

A Decorator of a certain subclass of an interface is simply a subclass that is on the same inheritance level. The difference between the subclass and its Decorator is that instead of implementing all the nterface operations itself, the Decorator simply maintains an instance of the subclass and forward the request to it after/before it adds decorations to the request. The idea enables decorators can be nested by any sequence without worry about what the decorated one is.

The Decorator helps decrease the height of the class hiararchy and is more flexible than pure inheritance. Sometime the abstract Decorator class can be omitted.

No comments: