Desgin Pattern : Strategy

本文探讨了在软件设计中使用策略模式来提高代码的扩展性和灵活性。通过对比没有使用策略模式的情况,文章详细介绍了几种实现运行时动态加载DLL的方法,包括虚拟方法、委托和反射等,并对每种方法进行了优缺点分析。

Problem: hard to expand and change

if...else if... else if...
switch...case...case...


Approch to achive Run time dynamic load dll
>>virtual method (protected)
>>delegation
>>reflection

===>Strategy

delegation: once fulfil input parameter and return value are the same, you can use:event handler
interface: classes need to have same abstract meaning
template method: strategy is not a class instance, only a algorithm, template method is a class, has relationship between parent class and child class. parent class has the whole workflow and child class change one or more steps.

 

Without Strategy:

 

With Strategy:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值