桥梁格局与战略格局有什么区别? [英] What is the difference between the bridge pattern and the strategy pattern?

查看:178
本文介绍了桥梁格局与战略格局有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试阅读有关毅力,维基百科和许多网站的许多文章。
我不了解桥梁模式和策略模式之间的差异。

I tried to read many articles on dofactory, wikipedia and many sites. I have no idea on differences between bridge pattern and the strategy pattern.

我知道它们都将抽象与实现分离,并可以在运行时更改实现时间。

I know both of them decouple an abstraction from its implementation and can change implementation at run time.

但我仍然不知道在哪种情况下,我应该使用策略,或在哪种情况下我应该使用桥梁。

But I still don't know in which situation I should use strategy or in which situation I should use bridge.

提前感谢

推荐答案

语义学。从维基百科


Strategy
模式的UML类图与Bridge模式的
的图相同。然而,这两个
设计模式在
的意图上是不一样的。虽然Strategy
模式是针对行为的,但
Bridge模式是为结构而设计的。

The UML class diagram for the Strategy pattern is the same as the diagram for the Bridge pattern. However, these two design patterns aren't the same in their intent. While the Strategy pattern is meant for behavior, the Bridge pattern is meant for structure.

上下文与
之间的耦合该策略比起b
中的
耦合在Bridge
模式中的实现更紧。

The coupling between the context and the strategies is tighter than the coupling between the abstraction and the implementation in the Bridge pattern.



据了解,当您抽取可从外部源提供的行为(例如,config可以指定加载一些插件程序集)时,您正在使用策略模式,而您正在使用桥接模式当您使用相同的结构使您的代码更整洁。实际的代码看起来很相似 - 你只是应用这些模式有些不同的原因。

As I understand it, you're using the strategy pattern when you're abstracting behavior that could be provided from an external source (eg. config could specify to load some plugin assembly), and you're using the bridge pattern when you use the same constructs to make your code a bit neater. The actual code will look very similar - you're just applying the patterns for slightly different reasons.

这篇关于桥梁格局与战略格局有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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