凝聚力和去耦力分别代表什么? [英] Cohesion and Decoupling, what do they represent?

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

问题描述

凝聚力和去耦力是什么?我找到了有关耦合的信息,但没有有关解耦的信息.

What are Cohesion and Decoupling? I found information about coupling but not about decoupling.

推荐答案

亚伦的这篇文章非常容易理解,我建议您阅读配员出版物

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 :

耦合:

如果元素变化,元素将耦合 一个迫使另一种改变.为了 例如,如果两个类继承自 共同的父母,然后改变一个 类可能需要更改 其他.考虑组合音频系统: 它紧密耦合,因为如果我们 想要从模拟变为数字 广播,我们必须重建整个 系统.如果我们从 分离,它将具有低耦合 我们可以换掉 接收者. 松散"的耦合特征 (即耦合度低的那些)是 易于维护.

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.

凝聚力:

元素的内聚力是一种度量 其职责是否构成了 有意义的单位.例如,一堂课 不能同时解析日期和网址 连贯的,因为它们是无关的 概念.想想一台机器 既洗衣服又洗碗- 不太可能两者都做得很好.2 另一个极端,可以解析的类 只有网址中的标点是 不太可能是连贯的,因为它 并不代表一个完整的概念.到 完成任何事情,程序员将 必须找到其他解析器 协议,主机,资源等. 具有高"连贯性的特征是 易于维护.

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天全站免登陆