How would you define the following code?
a) High cohesion
b) Low cohesion
I would say High as even though takeAndGlue()
does 2 things they are called with 2 separate methods, hence the stackTrace
is traceable.
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();
}
}
This class shows low cohesion because take() and glue() can be called separately but that makes no sense if not in the right order. In other words: take(), glue() should not be public.