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)
public abstract class Shape {
protected DrawAPI drawAPI;
protected Shape(DrawAPI drawAPI){
this.drawAPI = drawAPI;
}
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.