标签:灵活 买房 动态 color bst Stub 客户端 音乐 打电话
装饰设计模式
public interface Phone { public void call(); }
?
public abstract class BasicFunction implements Phone { private Phone p; public BasicFunction(Phone p) { this.p = p; } @Override public void call() { p.call(); } }
public class MusicFunction extends BasicFunction { public MusicFunction(Phone p) { super(p); } @Override public void call() { // TODO Auto-generated method stub super.call(); System.out.println("手机可以听歌了!!!!!!!!!"); } }
public class Test { public static void main(String[] args) { Iphone p = new Iphone(); MusicFunction p2 = new MusicFunction(p); p2.call(); // RingFunction p3 = new RingFunction(p); // p3.call(); } }
标签:灵活 买房 动态 color bst Stub 客户端 音乐 打电话
原文地址:https://www.cnblogs.com/nangongyibin/p/10184166.html