CQM-PolymorphismPlacebo

Routines of subclasses should not hide static routines of their parents

Required inputs: IR, RFG

A static routine of a superclass is visible in its subclass, but is hidden by another method with the same signature.

Motivation

An important use of inheritance is the realization of polymorphism for the implementation of a type hierarchy: The superclass declares interfaces and implements them if necessary. In the subclasses the possibility exists of covering inherited routines, in order to consider specifics of the subclass with the implementation accordingly. Due to the polymorphism the routines of those subclasses are called automatically, whose instance represents the object.

This possibility of executing certain implementations in dependence on current object types exists however only for object routines, not for class routines (static). If a static routine of a superclass is called, this call cannot be covered by an implementation in the subclass. The implementation of the superclass is always executed, regardless of whether the call is made via instances of subclasses. Although the inheritance structure and the coverages suggest polymorphism, the appropriate routines are not resolved polymorphic (Polymorphism placebo).

This rule is based on the CQM Quality Indicator: Polymorphieplacebo (p. 264-266).

Reference

Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.

Possible Messages

Key

Text

Severity

Disabled

hides_static_routine

This routine hides a static routine in a super class.

None

False

Options

include_structs

include_structs : bool = False

Whether structs are to be analyzed.