I do understand the SOLID Principles and LSP, but I want to be able to meausure how well a class diagram obeys to the LSP. Therefor I have found the "Value of LSP" metric, here is a guide how it should be used:
Metrics of Liskov Substitution Principles (LSP) The main key to this principle is the management of the inheritance hierarchy. The main metrics in this principle are NMI, NME and NMO. We specifies the NMI metric into NMIa the number of abstract methods inherited by the baseclass. NME metrics are the number of abstract methods defined by subclass, these definitions must be with the same method components (return type, name and parameter) like the baseclass property, whereas NMO metrics are the number of concrete methods overridden and overloading by subclass. This measurement is performed in a set of inheritance hierarchies, all of baseclass and subclasses pairs must be checked, to the lowest layer. The following is a technique for measuring class design conformity with LSP:
A)
A set of inheritance hierarchies, namely from
(DIT = 0) ⋀ (NOC \> 0) ⋀ (abstract)
to the largest DIT value at the lowest inheritance level. This set of hierarchies is called the Number of Hierarchies (NOH).
B)
This calculation is performed one by one between the baseclass inheritance pair and its subclasses in a set of inheritance hierarchies, namely by:
-
Calculate the number of baseclass-children (NOC).
-
Then calculate the value of ܰNMIa baseclass.
-
Then calculate NME and NMO from each subclass.
-
Match the value of NME and ܰNMIa for each pair of baseclass-subclass, make sure the values are the same. Then calculate NMO in the subclass, make sure that the NMO value is 0, if it is conform then it can be stated that the pair meets LSP, CLSP (Conform LSP).
-
Calculate the NOC value of each subclass, if
NOC > 0
, then repeat the calculation of step 2 (B) to the children of the subclass.
C)
Calculations can stop immediately when encountered
NMO > 0
the hierarchy NCLSP (Not Conform LSP).
D)
When NME is found to be smaller than ܰNMIa then check the subclass properties, if it is abstract, then continue the number 2 iteration (B) to their children, but if the concrete stops, the inheritance pair has subclasses that do not implement abstract methods, the hierarchy NCLSP.
E)
A set of inheritance hierarchies is stated to meet LSP when all inheritance pairs fulfill LSP requirements.
My question is if I start with an abstract Superclass (DIT=0)
then the NMIa is going to be 0 such as NME and NMO, because you can't override or extend unimplemented functions, so in this case it's always Conform to LSP. Is my assumption correct? Could you give some examples when a violation of LSP would be registered by the metric and when a class diagram would be LSP conform?
The original paper can be found here: https://easychair.org/publications/preprint_download/pmpT