Difference between Bridge pattern and Adapter pattern

后端 未结 9 1052
清歌不尽
清歌不尽 2020-11-29 19:16

What is the difference between the Bridge and Adapter patterns?

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 19:57

    Bridge is improved Adapter. Bridge includes adapter and adds additional flexibility to it. Here is how elements from Ravindra's answer map between patterns:

          Adapter  |    Bridge
        -----------|---------------
        Target     | Abstraction
        -----------|---------------
                   | RefinedAbstraction
                   |
                   |   This element is Bridge specific. If there is a group of 
                   |   implementations that share the same logic, the logic can be placed here.
                   |   For example, all cars split into two large groups: manual and auto. 
                   |   So, there will be two RefinedAbstraction classes.
        -----------|--------------- 
        Adapter    | Implementor
        -----------|---------------
        Adaptee    | ConcreteImplementor
    

提交回复
热议问题