您将如何定义以下代码?
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/