什么是高凝聚力以及如何使用/制造? [英] What is high cohesion and how to use it / make it?

查看:164
本文介绍了什么是高凝聚力以及如何使用/制造?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习计算机编程,并且在多个地方偶然发现了凝聚力的概念,并且我知道对于软件来说,具有高度凝聚力"是可取的,但这意味着什么?我是一名Java,C和Python程序员,从《 C ++ Primer》一书中学习C ++,该书提到凝聚力而没有将其纳入索引中,您能指出我一些与此主题相关的链接吗?我找不到有关计算机科学凝聚力的Wikipedia页面,因为它只是说这是定性的度量,没有给出真实的代码示例.

I'm learning computer programming and at several places I've stumbled upon the concept of cohesion and I understand that it is desirable for a software to have "high cohesion" but what does it mean? I'm a Java, C and Python programmer learning C++ from the book C++ Primer which mentions cohesion without having it in the index, could you point me to some links about this topic? I did not find the wikipedia page about computer science cohesion informative since it just says it's a qualitative measure and doesn't give real code examples.

推荐答案

高内聚性是指您的班级做得很好.内聚力低是指班级从事很多没有太多共同点的工作.

High cohesion is when you have a class that does a well defined job. Low cohesion is when a class does a lot of jobs that don't have much in common.

让我们举个例子:

您有一个将两个数字相加的类,但是同一类会创建一个显示结果的窗口.这是一个低内聚的类,因为窗口和加法操作没有太多共同之处.窗口是程序的可视部分,添加功能是其背后的逻辑.

You have a class that adds two numbers, but the same class creates a window displaying the result. This is a low cohesive class because the window and the adding operation don't have much in common. The window is the visual part of the program and the adding function is the logic behind it.

要创建高凝聚力的解决方案,您必须创建一个Window类和一个Sum类.窗口将调用Sum的方法来获取结果并显示出来.这样,您将分别开发应用程序的逻辑和GUI.

To create a high cohesive solution, you would have to create a class Window and a class Sum. The window will call Sum's method to get the result and display it. This way you will develop separately the logic and the GUI of your application.

这篇关于什么是高凝聚力以及如何使用/制造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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