Intention
Add some extra responsibilities to an object dynamically. For added functionality, the decorator mode is more flexible than generating subclasses.
The source class is a decorated class, and the decorator class is a decorative class that can dynamically add some functionality to the source class.
Public interface Sourceable {public void method ();
public class Source implements sourceable{@Overridepublic void method () {System.out.println ("This is original method!"); }}
public class Decorator implements Sourceable{private source Source;public Decorator (source source) {super (); This.source = Source;} @Overridepublic void Method () {System.out.println ("before decorator!"); Source.method (); System.out.println ("after decorator!");}}
Transferred from: http://blog.csdn.net/zhangerqing/article/details/8239539
Java Learning Note-design pattern 8 (Adorner mode)