今天我的困境来自于试图理解为什么在策略和桥梁模式可以实施时存在重叠的原因。设计模式 - 策略与桥梁(重叠设计)
下面是桥接模式(从抽象的抽象实现)
// 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);
}
}
现在这里是战略格局 - 一类的行为或它的算法可以在运行时更改。计算器将其操作委托给策略
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);
}
}
这两种模式都涉及丢弃封装功能的策略对象。请帮助Bridge模式(结构)和策略模式(行为)之间的明显差异。我遇到的另一个困惑是他们在不同的知识雨伞下。
可能的[策略与桥接模式]重复(http://stackoverflow.com/questions/5863530/strategy-vs-bridge-patterns) –
http://stackoverflow.com/questions/5863530/strategy-vs -bridge-patterns,http://stackoverflow.com/questions/464524/what-is-the-difference-between-the-bridge-pattern-and-the-strategy-pattern – Andrew
策略是行为模式,Bridge是结构模式。看看http://stackoverflow.com/questions/464524/what-is-the-difference-between-the-bridge-pattern-and-the-strategy-pattern –