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.

Program

https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/JAVA/DesignPattern/src/decorator

Run TestMain.java to test.

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

Reference:

Decorator pattern

Grate answer at stackoverflow

No comments:

Post a Comment