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

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

问题描述

我在理解低耦合和高内聚这句话时有问题.我已经用谷歌搜索并阅读了很多关于此的内容,但仍然发现它很难理解.

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.

据我所知,高内聚意味着我们应该有专门用于执行特定功能的类.希望这是正确的?就像信用卡验证类,专门用于验证信用卡.

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:

截图来自课程.

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

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