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_VARAction FB.ACT:
i := FALSE;Method FB.METH:
METHOD METH : BOOL
VAR_INPUT
c : BOOL;
END_VARMETH := c;
i := TRUE;Method FB.METH2:
METHOD METH2 : INT
VAR_INPUT
END_VARMETH2 := SEL(b,3,4);For the metric Lack of Cohesion Of Methods (LCOM) , the result for FB:
- Object pairs without cohesion (5 pairs):
FB,FB.ACTFB,FB.METHFB,FB.METH2FB.ACT,FB.METH2FB.METH,FB.METH2- Object pairs with cohesion (1 pair):
FB.ACT,FB.METH(both usei)- LCOM = number of object pairs without cohesion - number of object pairs with cohesion = 5 - 1 = 4