Design Pattern - Strategy and Bridge (add-in in design)

Today, my dilemma arises from trying to understand why there is a coincidence in how strategy and bridge can be implemented.

Here is a bridge template (abstraction of an implementation from an abstraction)

// Shapes object structure will not be concerned how they draw themselves
public abstract class Shape {
   protected DrawAPI drawAPI;

   protected Shape(DrawAPI drawAPI){
     this.drawAPI = drawAPI;
   }
   // This could also be put in the subcla
   public void draw() {
     drawAPI.drawCircle(radius,x,y);
   }
}

Now here is the strategy template - the behavior of a class or its algorithm can be changed at runtime. Calculator delegates its operations to strategies

public class Calculator{
  private Strategy strategy;

  public Calculator(Strategy strategy){
    this.strategy = strategy;
  }

  public int executeStrategy(int num1, int num2){
     return strategy.doOperation(num1, num2);
  }
}

Both of these patterns include dropping strategy objects that encapsulate functionality. Please help with the clear difference between the bridge pattern (structural) and the strategy pattern (behavioral). Another confusion I am experiencing is that they are under different areas of knowledge.

+6
3

Strategy Pattern , . , , B2B B2C, . . , , () ​​ . , , . .

+1

.

Bridge , , . , .

. , Bridge, , .

+3

. , , . .

, , .

0

Source: https://habr.com/ru/post/1017161/


All Articles