凝聚力和解耦 [英] Cohesion and Decoupling

查看:178
本文介绍了凝聚力和解耦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我什么是凝聚力和解耦?我找到了耦合,但在任何地方都没有去耦。我需要了解它们的含义。

Can anyone tell me what are Cohesion and Decoupling? I found coupling but there is no Decoupling anywhere. I need to learn their meanings.

任何帮助都将不胜感激。感谢您的回复。

Any help will be appreciated. Thanks for replying.

推荐答案

Aaron的文章非常有助于理解,我也建议您阅读manning出版物< a href =http://www.manning.com/walls2/ =noreferrer> Spring in Action 一书,他们给出了很好的例子,说明弹簧如何解决这个问题,它肯定会提高你的理解力这个。

That article from Aaron is very good for understanding, also I'd recommend that you read manning publications Spring in Action book, they give very good examples on how the spring solves that problem it will definitely improve your understanding of this.

编辑:

我在这本伟大的书中遇到了这个在测试指导下调用增长的面向对象软件:

I came accross this in this great book called Growing object oriented software guided by tests :

耦合:


如果
的变化迫使另一个变化,则元素会耦合。对于
示例,如果两个类继承自
公共父级,则一个
类中的更改可能需要更改
other。想想一个组合音频系统:
这是紧密耦合的,因为如果我们
想要从模拟到数字
无线电,我们必须重建整个
系统。如果我们从
分离组装一个系统,它将具有低耦合
,我们可以换掉
接收器。 松散耦合功能
(即低耦合的那些)是
更容易维护。

Elements are coupled if a change in one forces a change in the other. For example, if two classes inherit from a common parent, then a change in one class might require a change in the other. Think of a combo audio system: It’s tightly coupled because if we want to change from analog to digital radio, we must rebuild the whole system. If we assemble a system from separates, it would have low coupling and we could just swap out the receiver. "Loosely" coupled features (i.e., those with low coupling) are easier to maintain.

凝聚力:


元素的凝聚力是一个衡量
的措施责任形成
有意义的单位。例如,解析日期和URL的类
不是
coherent,因为它们与
概念无关。想想一台机器,
洗掉衣服和餐具 - 这是
不太可能同时做得很好.2在
另一个极端,一个解析
的类只有URL中的标点符号
不太可能是连贯的,因为
并不代表​​一个完整的概念。要
完成任何事情,程序员将
必须为
协议,主机,资源等找到其他解析器。
具有高一致性的功能是
更容易维护。

An element’s cohesion is a measure of whether its responsibilities form a meaningful unit. For example, a class that parses both dates and URLs is not coherent, because they’re unrelated concepts. Think of a machine that washes both clothes and dishes—it’s unlikely to do both well.2 At the other extreme, a class that parses only the punctuation in a URL is unlikely to be coherent, because it doesn’t represent a whole concept. To get anything done, the programmer will have to find other parsers for protocol, host, resource, and so on. Features with "high" coherence are easier to maintain.

这篇关于凝聚力和解耦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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