“低耦合和高凝聚力"是什么意思 [英] What does 'low in coupling and high in cohesion' mean

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

问题描述

我在理解语句low in coupling and high in cohesion时遇到问题.我已经在Google上搜索并阅读了很多相关内容,但仍然很难理解.

I have problems understanding the statement low in coupling and high in cohesion. I have googled and read a lot about this, but still finding it hard to understand.

据我了解,High cohesion的意思是,我们应该具有专门用于执行特定功能的类.希望这是正确的吗?就像信用卡验证类一样,该类专门用于仅验证信用卡.

To what I understand is High cohesion means, that we should have classes that are specialized to perform a particular function. Hope this is correct? Like a credit card validation class, which is specialized to validate credit cards only.

仍然不了解低耦合的含义是什么?

And still don't understand what low Coupling means?

推荐答案

我相信的是:

内聚性是指模块/类的元素之间的结合程度,建议相关代码应彼此靠近,因此我们应争取较高的内聚力,并将所有相关代码尽可能紧密地绑定在一起可能的.它与模块/类中的元素有关.

Cohesion refers to the degree to which the elements of a module/class belong together, it is suggested that the related code should be close to each other, so we should strive for high cohesion and bind all related code together as close as possible. It has to do with the elements within the module/class.

耦合是指不同模块/类之间相互依赖的程度,建议所有模块都应尽可能独立,这就是低耦合的原因.它与不同模块/类中的元素有关.

Coupling refers to the degree to which the different modules/classes depend on each other, it is suggested that all modules should be independent as far as possible, that's why low coupling. It has to do with the elements among different modules/classes.

可视化整个图片会有所帮助:

To visualize the whole picture will be helpful:

该屏幕截图来自库拉(Coursera).

这篇关于“低耦合和高凝聚力"是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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