design_model(7)bridge

1.桥接模式

基于类的最小设计原则,通过使用封装、聚合及继承等行为让不同的类承担不同的职责。它的主要特点是把抽象(Abstraction)与行为实现(Implementation)分离开来,从而可以保持各部分的独立性以及应对他们的功能扩展。

2.实例

public interface Brand {

}

public class Huasuo implements  Brand{
	
}

public interface  Computer {

}

public class Desktop  implements Computer{
   private Brand  brand;

  public Desktop(Brand brand) {
	super();
	this.brand = brand;
  }
  
}

public class Client {
   public static void main(String[] args) {
	 Desktop desktop = new Desktop(new Huasuo());
  }
}
原文地址:https://www.cnblogs.com/gg128/p/9570160.html