我在读关于
SOLID's Open/Closed Principle
今天我记得的第一个例子是
ViewDragHelper
上课时间
支持库。
课程详情如下:
// allowing a user to drag and reposition views
public class ViewDragHelper {
private final Callback mCallback;
public static ViewDragHelper create(..., Callback cb)
public abstract static class Callback {
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { }
public int getViewHorizontalDragRange(View child) {
return 0;
}
public abstract boolean tryCaptureView(View child, int pointerId);
public int clampViewPositionHorizontal(View child, int left, int dx) {
return 0;
}
}
}
我想弄清楚这是不是
strategy pattern
. 实际上好像是的。这就是
Context
(
视图绘图工具
Strategy
抽象(
Callback
类)。但有两点:
-
-
战略实施的行为影响战略的实施
上下文
tryCaptureView
方法),在
Strategy pattern
说明a
上下文
战略
或者其他一些模式或者只是实现这样一个共同的概念,比如
回拨
?