CQM-ClassIncest

A superclass should not be dependant of any of its subclasses

Required inputs: RFG

A superclass must not have any knowledge of its direct or indirect sub classes. This includes accessing fields or methods of its subclasses or knowing the concrete type.

Motivation

A superclass must not have any dependencies to its subclasses, because such dependencies can lead in some situations to changes in the generalization being necessary as soon as a new concretion is defined. A typical example of such a dependency is type queries in the generalization, so that the concretion may have different behavior at runtime depending on the object that is actually present. These dependencies can be resolved e.g. by polymorphism, by changing the inheritance relationship or by consistent use of interfaces.

This rule is based on the CQM Quality Indicator: Klasseninzest (p. 231-233).

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

class_incest

This superclass depends on at least one of its subclasses.

None

False

Options

include_structs

include_structs : bool = True

Whether structs are to be analyzed.
 

include_template_classes

include_template_classes : bool = True

Whether template classes are to be analyzed.