java - 关于java编程中内聚性的探究

标签 java cohesion ocpjp

您将如何定义以下代码?

a) 高内聚力

b) 低内聚力

我想说高,因为即使 takeAndGlue() 做了 2 件事,它们是用 2 个单独的方法调用的,因此 stackTrace 是可跟踪的。

public class Assembler()
{
    public void take()
    {
        System.out.println("Take the thing");
    }
    public void glue()
    {
        System.out.println("Glueing the thing");
    }
    public void takeAndGlue()
    {
        take();
        glue();
    }
}

最佳答案

维基百科说..

As applied to object-oriented programming, if the methods that serve the given class tend to be similar in many aspects, then the class is said to have high cohesion.

在你的例子中,这三个方法都在做与汇编相关的工作,这个类可以说具有很高的内聚性。

关于java - 关于java编程中内聚性的探究,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18527809/

相关文章:

java - 在一个基准内使用广泛的输入

java - 不使用Spring等时如何将Swing GUI与业务逻辑分离

java - 有人能解释一下这个关于枚举的程序在java中是如何工作的吗?

scjp - 树集子集

c# - 去除耦合然后模拟单元测试

java - Java中垃圾回收的合格变量

java - java中一个方法是public/private/other是什么意思?

java - PowerMockito : got InvalidUseOfMatchersException when use matchers mocking static method

java - 在线程 "main"java.lang.NoSuchMethodError : main? 中不断收到异常

c - 开源还是免费软件 C 代码度量工具?