装饰器模式
public interface ISource { public void operation(); }
?
public class Source implements ISource { public void operation() { System.out.println("原始类方法"); }}
?
public class Decorator1 implements ISource { private ISource source; public Decorator1(ISource source){ this.source = source; } public void operation() { System.out.println("第一个装饰器前"); source.operation(); System.out.println("第一个装饰器后"); }}
?
public class Decorator2 implements ISource { private ISource source; public Decorator2(ISource source){ this.source = source; } public void operation() { System.out.println("第二个装饰器前"); source.operation(); System.out.println("第二个装饰器后"); }}
?
public class Decorator3 implements ISource { private ISource source; public Decorator3(ISource source){ this.source = source; } public void operation() { System.out.println("第三个装饰器前"); source.operation(); System.out.println("第三个装饰器后"); }}
?
public class Client { public static void main(String[] args) { ISource source = new Decorator3(new Decorator2(new Decorator1(new Source()))); source.operation(); }}
?
?