Friday, May 16, 2014

Decorator Pattern in Java

Simple Note

(From wiki):
The decorator pattern (also known as Wrapper, an alternative naming shared with the Adapter pattern) is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.


Run to test.

OldSiren().alarm() will only output a message in console, BeepDecorator can wrap OldSiren to add a beep.


Decorator pattern

Grate answer at stackoverflow

No comments:

Post a Comment