首页 > 其他 > 详细

The Strategy Pattern 策略模式

时间:2014-04-04 16:29:18      阅读:453      评论:0      收藏:0      [点我收藏+]
策略模式定义了算法族,分别封装起来,让它们之间可以相互替换,此设计模式让算法的变化独立于使用算法的客户。
The Strategy Pattern defines a family of algorithms,encapsulates each one, and makes them interchangeable.
Strategy lets the algorithm vary independently from clients that use it.

设计原则一:找出应用中可能需要变换之处,把它独立出来,不要和那些不需要变换的代码混在一起。
           把会变化的部分取出并封装起来,以便以后可以轻松的改动或补充此部分,而不影响不需要变化的其他部分。

设计原则二:针对接口编程,而不是针对实现编程。

设计原则三:多用组合,少用继承。
           使用组合建立系统具有很大的弹性,不仅可以将算法族封装成类,更可以“在运行时动态的改变行为”,只要组合的行为对象符合正确的标准接口即可。
 bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣

The Strategy Pattern 策略模式,布布扣,bubuko.com

The Strategy Pattern 策略模式

原文:http://blog.csdn.net/smileteo/article/details/22932439

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!