What is the difference between the bridge pattern and the strategy pattern?

后端 未结 14 2168
予麋鹿
予麋鹿 2020-11-30 20:37

I tried to read many articles on dofactory, wikipedia and many sites. I have no idea on differences between bridge pattern and the strategy pattern.

I know both of t

14条回答
  •  长情又很酷
    2020-11-30 21:00

    Bridge: ( A structural pattern)

    Bridge pattern decouples abstraction and implementation and allows both to vary independently.

    Use this pattern when :

    1. Abstractions and implementations have not been decided at compile time
    2. Abstractions and implementations should be changed independently
    3. Changes in implementation of abstraction should not affect caller application
    4. Client should be insulated from implementation details.

    Strategy: ( Behavioural pattern)

    Strategy patterns enable you to switch between multiple algorithms from a family of algorithms at run time.

    Use Strategy pattern when :

    1. Multiple versions of algorithms are required
    2. The behaviour of class has to be changed dynamically at run time
    3. Avoid conditional statements

    Related posts:

    When do you use the Bridge Pattern? How is it different from Adapter pattern?

    Real World Example of the Strategy Pattern

提交回复
热议问题