interface Sourceable{
public void method();
}
class Source implements Sourceable{
@Override
public void method() {
System.out.println(“被修饰对象”);
}
}
class Decorator implements Sourceable{
private Sourceable source;
public Decorator(Sourceable source) {
super();
this.source=source;
}
@Override
public void method() {
System.out.println(“开启装饰器”);
source.method();
System.out.println(“结束装饰器”);
}
}
public class Test1 {
public static void main(String[] args) {
Sourceable source= new Source();
Sourceable decorator = new Decorator(source);
decorator.method();
}
}
装饰器模式
最新推荐文章于 2024-10-04 08:38:41 发布