[英]Is this a strategy pattern or just a callback?
今天,我正在閱讀有關SOLID's Open/Closed Principle
,我記得的第一個示例是Android支持庫中的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
( ViewDragHelper
類)和Strategy
抽象( Callback
類)。 但是有兩點:
Context
(您可以在tryCaptureView
方法中tryCaptureView
視圖位置或禁止拖動操作),而在Strategy pattern
描述中, Strategy
似乎對Context
沒有任何影響(即僅產生或使用某些數據) 。 這是一種Strategy
還是某種其他模式,或者僅僅是諸如Callback
之類的通用概念的實現?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.