惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 叶小钗
F
Fortinet All Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 最新话题
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
Recent Announcements
Recent Announcements
Recent Commits to openclaw:main
Recent Commits to openclaw:main
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
IT之家
IT之家
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
J
Java Code Geeks
M
MIT News - Artificial intelligence
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
G
Google Developers Blog
W
WeLiveSecurity
罗磊的独立博客
P
Privacy & Cybersecurity Law Blog
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
T
Tailwind CSS Blog
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
Blog — PlanetScale
Blog — PlanetScale
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed

博客园 - ColorSky

小议winForm的热键 一定要找到你--IE隐藏文件 One sentence humor Self-service How do you add reference dll from GAC? 其实它不是我想象 关于目标 英语文化陷井 Everyday English - Glove Troubleshooting for Asp.net CS0016 error [ZZ]C#四种排序算法 唐僧的家书 管理的问题-聪明和笨的程序员 一个应用程序在某一时刻,到底是用了多少内存? 揭秘devenv 如何以两种启动模式启动 程序员,为你的程序而骄傲吧 算法的力量 minute_DesignPatternExplained(2) 转载同事写的:2006TechED感想
minute_DesignPatternExplained(4)
ColorSky · 2006-12-08 · via 博客园 - ColorSky

继续我们的学习, 9章。Strategy模式
回顾我们的目标:
·    按接口编程
·    尽量用聚合代替继承
·    找出变化并封装之
Strategy模式
例:比如需要显示点,线,正方形,圆。
 
如果还需要一种带有特殊边线的正方形,我们从正方形继承,重用Square中的代码,只是覆盖DrawBorder方法。
导致的问题:
弱内聚:                    如果有许多边线类型,Square还要关心所有的边线绘制。
减少复用可能性                    当我们为不同边线编写了代码,并加入Square及其派生类,怎样才能将这些代码复用于其它形状呢?
无法根据变化很好的伸缩            如果需求变更,要求两种不同的底纹怎么办?为了应对所有选择,要不断特化Square

优秀的解决方法:
标准图:
 
意图                    可以根据上下文,使用不同的业务规则和算法
问题                    对所需算法的选择取决于发出请求的客户或要处理的数据,算法预料会发生变化。
解决方案                将算法封装到一个单独的类中
                    将这个算法类包含在客户对象中

参与者和协作者                Strategy指定了如何使用不同的算法
                    各Concrete Strategy 实现了这些不同的算法
                    Context通过类型为Strategy的引用使用具体的Concrete Strategy对象。
                    Context将来自客户的请求发个Strategy

效果                    必须以相同的接口调用所有算法
分离了业务规则和客户对象
                    定义了一系列算法
                    避免使用Switch语句

实现                    让使用算法的类(Context)包含一个抽象策略类(Strategy)
该抽象类定义一个抽象方法指定如何调用
每个派生类按需要实现具体算法

-End-