Strategy 定义一系列算法或策略,把它们封闭起来,并且使它们相互可以替换。各算法或策略可以独立于客户程序而变化。

产品类
接口,定义策略操作
如果用户没有注册,根据相似性推荐产品
根据相似性推荐产品的隐形
根据客户最近的购买情况,推荐产品
购买情况推荐产品隐形
公司正在促销
随机推荐
Customer类,根据条件选择推荐隐形
The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets algorithm vary independently from clients use it.
We can see three design principle:
1.Identify the aspects of your application that vary and separate them from what stays the same.
2.Program to an interface, not an implemention.
3.Favor composition over inheritance.
Can you see it?
posted @ 2007-01-11 15:58  南守拥  阅读(340)  评论(0编辑  收藏  举报