CQM-SimulatedPolymorphism

An objects type is checked multiple times inside one routine

Required inputs: IR

A routine simulates polymorphism by checking the type of an object multiple times. This rule is restricted to the number of typeid uses.
Motivation

The type safety of the object-oriented languages considered here ensures that only those messages, which posses the same type as the identifier in the source code, can be sent. By declaring an identifier with the type of an interface, can be ensure that only the functionality of the interface is used, for example. The deliberate independence from the actual type at runtime achieved in all these cases can be circumvented by type checks (in C++, for example, using the typeid functionality).

If an object is asked for its type at runtime and different subsequent operations are called depending on it, then polymorphism can be simulated by this. In contrast to the genuine polymorphism, with which the run time system determines the actual addressee of a message and the programmer does not have to store the distinctions statically in the code any longer, this simulated polymorphism is however very maintenance-unfriendly. Thus a new addressee of a message must be made known at all places with simulated polymorphism. Also any change of addressees (e.g. name and location) has to be done multiple times in a decentralized way. Overall, the structures created by simulated polymorphism pose a great risk to the long-term sustainability of a system.

This rule is based on the CQM Quality Indicator: simulierte Polymorphie (p. 284-287).

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

type_casts

This routine simulates polymorphism by casting an object to a different type multiple times.

None

False

type_checks

This routine simulates polymorphism by checking the type of an object multiple times.

None

False

type_checks_or_casts

This routine simulates polymorphism by checking the type of an object, or casting it, multiple times.

None

False

Options

identify_dynamic_casts

identify_dynamic_casts : bool = False

Whether dynamic_casts should also be counted.
 

max_number_of_typechecks

max_number_of_typechecks : int = 1

The maximum number of times an object type can be checked before its considered simulated polymorphism.