战略格局与授权模式的差异 [英] Difference between Strategy pattern and Delegation pattern

查看:131
本文介绍了战略格局与授权模式的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

策略模式与授权模式(不是代理)有什么区别?

What is the difference between Strategy pattern and Delegation pattern (not delegates)?

推荐答案

策略模式是一个非常具体的设计解决了一个常见的软件问题。
的策略模式意味着将有一个名为Strategy(或者将Strategy作为名称的一部分)的界面

the strategy pattern is a very specific design solution to a common software problem. the strategy pattern implies that there will be


  • 。这个接口应该有一个叫做execute()的方法。

  • 一个或多个具体的类叫做ConcreteStrategyA,ConcreteStrategyB等,实现了Strategy接口。

  • 还应该有一个包含策略的上下文类

委托比模式更多。代表团意味着,不是单一对象负责所有事物,而是将责任委托给其他对象。这是一个常见技术的原因是它通过减少耦合和增加凝聚力来实现软件开发的两个更基本的原则。

delegation is more a principal than a pattern. delegation implies that instead of having a single object be in charge of everything, it delegates responsibilities to other objects. the reason this is a common technique is that it enforces two even more fundamental principals of software development by lessening coupling and increasing cohesiveness.

说完这一切,不用担心关于模式。专注于校长,如果您觉得您的解决方案可以改进 - 查看模式,看看是否有更好的捕鼠器。如果你专注于模式而不是校长,你会发现自己在所有的模式和实现模式中迷失了,以实现模式...

Having said all that, don't worry about patterns. Focus on the principals and if you feel your solution could be improved upon - look to the patterns to see if there is a better mousetrap. If you focus on patterns instead of principals, you will find yourself getting lost in all the patterns and implementing patterns for the sake of implementing patterns...

这篇关于战略格局与授权模式的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆