使用HttpServletRequestWrapper包装HttpServletRequest的目的是什么?这样做我们可以获得什么好处?
今天,我的困境来自于试图理解为什么战略和桥梁模式的实施方式存在重叠.
这是Bridge Pattern(从抽象中抽象出一个实现)
// 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);
}
}
Run Code Online (Sandbox Code Playgroud)
现在是策略模式 - 可以在运行时更改类行为或其算法.计算器会将其操作委派给策略
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这两种模式都涉及丢弃封装功能的策略对象.请帮助解决桥梁模式(结构)和战略模式(行为)之间的明显差异.我遇到的另一个困惑是他们处于不同的知识范围内.