设计模式之修饰者模式

来源:互联网 发布:人工智能上市公司 编辑:程序博客网 时间:2024/06/05 11:10

public interface sourceable{

public void method();

}


class source implements sourceable{

public void method(){

System.out.println("this is orginal method");

}

}


class decotor implements sourceable{

private Sourceable source;

public void decotor(Sourceable sourece){

this.method();

}

public void method(){

System.out.println("this is 1 ");

source.method();

System.out.println("this is 2");

}

}


public class Test{

public void static void main(String[] args){

Sourceabe source=new Sourceable();

dector d=new dector(source);

d.method();

}

}