一.概述 命令模式 二.代码 1.Client.java public class Client { public void request(Server server){ server.addCommand(new TextCommand()); server.addCommand(new ImageCommand()); server.doSomething(); } } 2.Server.java public class Server { private List<Command> c…
一.概述 1.桥接模式的应用情况:(1)两个维度扩展(2)排列组合 二.代码 1.Gift.java public class Gift { protected GiftImpl giftImpl; } 2.GiftImpl.java public class GiftImpl { } 3.WarmGift.java public class WarmGift extends Gift { public WarmGift(GiftImpl giftImpl) { //调用父类的giftImpl…
一.概述 二.代码 1.Animal.java public interface Animal { public void bark(); } 2.Dog.java public class Dog implements Animal { @Override public void bark() { System.out.println("Dog wang wang !"); } } 3.Cat.java public class Cat implements Animal { @Ov…