当前位置: 代码迷 >> Java相关 >> 装饰器模式与代理模式的区别解决方案
  详细解决方案

装饰器模式与代理模式的区别解决方案

热度:895   发布时间:2013-02-25 21:47:15.0
装饰器模式与代理模式的区别
如题

------解决方案--------------------------------------------------------
装饰模式你可以这样理解,就像糖一样,卖的时候商家大多要在外面包一层糖纸,其实原本还是糖。例子:
Java code
public interface Sourcable {    public void go();}public class Source implements Sourcable {    public void go() {        System.out.println("Source method go()");    }}public class Decorator implements Sourcable {    private Sourcable sourcable;        public Decorator(Sourcable sourcable){        this.sourcable = sourcable;    }        public void go() {                //这里可以有你的处理        sourcable.go();                //这里可以有你的处理    }}
  相关解决方案