Lack of Cohesion Of Methods - LCOM

Title short form

LCOM

Categories

Maintainability, reusability

Definition

Cohesion = pairs of methods without common instance variables minus pairs of methods with common instance variables

The metric is calculated using the following formula:

MAX(0, <number of object pairs without cohesion> - <number of object pairs with cohesion> )

Further information

LCOM: Lack of Cohesion of Methods

The cohesion between function blocks, their actions, transitions and methods describes whether they access the same variables.

The lack of cohesion of methods describes how strongly the objects of a function block are connected to each other. The lower the lack of cohesion, the stronger the connection between the objects.

Function blocks with a high lack of cohesion are likely to be involved in many different tasks and therefore violate the principle of unambiguous responsibility.

Sample:

Function block FB:

FUNCTION_BLOCK FB
VAR_INPUT
    a    : BOOL;
END_VAR
VAR
    i,b  : BOOL;
END_VAR

Action FB.ACT:

i := FALSE;

Method FB.METH:

METHOD METH : BOOL
VAR_INPUT
    c    : BOOL;
END_VAR
METH := c;
i := TRUE;

Method FB.METH2:

METHOD METH2 : INT
VAR_INPUT
END_VAR
METH2 := SEL(b,3,4);

For the metric Lack of Cohesion Of Methods (LCOM) , the result for FB: