桥接模式
package com.life.design.bridge; public abstract class Computer { protected Brand brand; public Computer(Brand brand) { this.brand = brand; } public void info(){ brand.info(); } }
package com.life.design.bridge; public class Desktop extends Computer { public Desktop(Brand brand) { super(brand); } @Override public void info() { super.info(); System.out.println("台式机"); } }
package com.life.design.bridge; public interface Brand { void info(); }
package com.life.design.bridge; public class Apple implements Brand { @Override public void info() { System.out.print("苹果"); } }