http://www.cnblogs.com/wuyuegb2312/archive/2013/04/09/3008320.html
public static void main(String[] args) { Singleton single = Singleton.getInstance(); System.out.println(single3.about()); } }
public static void main(String[] args) { FruitFactory factory = new FruitFactory(); Fruit apple = factory.create(Apple.class); apple.getColor(); Fruit oringe = factory.create(Apple.class); oringe.getColor(); }
public static void main(String[] args) { Fruit apple = new Apple(); // Fruit 是一个抽象类(水果类模板),所有水果都继承它 apple.getColor(); Fruit oringe = new Oringe(); oringe.getColor(); }
Handle A_handle = new Handle(); Handle B_handle = new Handle(); Handle C_handle = new Handle(); A.setNextHandle(B); B.setNextHandle(C);
Component c1 = new ConcreteComponent (); //首先创建需要被装饰的原始对象(即要被装饰的对象) Decorator decoratorA = new ConcreteDecoratorA(c1); //给对象透明的增加功能A并调用 decoratorA .operation(); // decoratorA 对c1对象进行了装饰,
interface TwoSocket { // 二孔插头 public void twoSocket(); } class ThreeSocket { // 三孔插头 public void threeSocket() { System.out.println("i'm three socket"); } } public class Adapter extends ThreeSocket implements TwoSocket{ // 适配器,同时有二孔和三孔 public void twoSocket() { // 即使使用二孔插头也能插三孔插头 super.threeSocket(); } public static void main(String[] args) { TwoSocket t = new Adapter(); // 使用适配器 t.twoSocket(); } }