橋接模式

壹頁書發表於2017-03-29
http://www.cnblogs.com/java-my-life/archive/2012/05/07/2480938.html

http://alicharles.com/article/jdk-bridge-pattern/



  1. abstract class Abstraction {  
  2.   
  3.     protected Implementor impl;  
  4.   
  5.     public Abstraction(Implementor impl) {  
  6.         this.impl = impl;  
  7.     }  
  8.   
  9.     // 示例方法  
  10.     public void operation() {  
  11.   
  12.         impl.operationImpl();  
  13.     }  
  14. }  
  15.   
  16. class RefinedAbstraction extends Abstraction {  
  17.   
  18.     public RefinedAbstraction(Implementor impl) {  
  19.         super(impl);  
  20.     }  
  21.   
  22.     // 其他的操作方法  
  23.     public void otherOperation() {  
  24.   
  25.     }  
  26. }  
  27.   
  28. abstract class Implementor {  
  29.     /** 
  30.      * 示例方法,實現抽象部分需要的某些具體功能 
  31.      */  
  32.     public abstract void operationImpl();  
  33. }  
  34.   
  35. class ConcreteImplementorA extends Implementor {  
  36.   
  37.     @Override  
  38.     public void operationImpl() {  
  39.         // 具體操作  
  40.     }  
  41.   
  42. }  
  43.   
  44. class ConcreteImplementorB extends Implementor {  
  45.   
  46.     @Override  
  47.     public void operationImpl() {  
  48.         // 具體操作  
  49.     }  
  50.   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-2136241/,如需轉載,請註明出處,否則將追究法律責任。

相關文章