- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
耦合策略和非耦合策略有什么区别?
谢谢回答。
最佳答案
当策略类知道上下文时,或者当客户端知道策略具体类时,策略是耦合的。
我们可以阅读 here (有一些小的修改):
Usually each strategy need data from the context or have to return some processed data to the context. This can be achieved in 2 ways.
- creating some additional classes to encapsulate the specific data.
- passing the context object itself to the strategy objects. The strategy object can set returning data directly in the context.
When data should be passed, the drawbacks of each method should be analyzed. For example, if some classes are created to encapsulate additional data, a special care should be paid to what fields are included in the classes. Maybe in the current implementation all required fields are added, but maybe in the future some new strategy concrete classes require data from context which are not included in those additional classes. Another fact should be specified at this point: it's very likely that some of the strategy concrete classes will not use fields passed to it in the additional classes.
In the classic implementation of the pattern the client should be aware of the strategy concrete classes. In order to decouple the client class from strategy classes is possible to use a factory class inside the context object to create the strategy object to be used. By doing so the client has only to send a parameter (like a string) to the context asking to use a specific algorithm, being totally decoupled of strategy classes.
关于design-patterns - 策略模式 : coupled strategy vs uncoupled strategy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21456722/
耦合策略和非耦合策略有什么区别? 谢谢回答。 最佳答案 当策略类知道上下文时,或者当客户端知道策略具体类时,策略是耦合的。 我们可以阅读 here (有一些小的修改): Usually each st
我遇到了 Python3.2 的问题。如果一个类装饰了父类的一个函数并且也有一个析构函数,那么该类的实例永远不会被垃圾回收。 下面是一些说明问题的示例代码: def super_simple_deco
我有以下模型和关联: SuccessCriterion has_many :requirements has_many :findings, through: :requirements Re
我是一名优秀的程序员,十分优秀!