CQM-RejectedInheritanceInterface¶
Overriding should not reduce the functionality or accessibility of a routine
Required inputs: IR
A routine of a superclass is overridden in a subclass, so that
it is either empty, returns only a nullptr, or has a lower
visibility.
Motivation
In general, the use of inheritance assumes the validity of the Liskov Substitution Principle (LSP). This states that objects of a derived class can in principle be used instead of a base class object. The prerequisite for this is the complete support of all inherited interfaces by the subclass.
A class violates the LSP if it does not fully support the interface of its superclass. This is the case if the class overwrites or implements methods of the superclass with empty methods or restricts their visibility (in the latter case, the interface is only »secretly« supported via the type of the superclass; it is no longer present through the subclass).
Using such classes as instances of superclasses can lead to unexpected runtime problems, because clients usually use the interface of the superclass and expect all subclass objects to fully support this interface as well.
This rule is based on the CQM Quality Indicator: ausgeschlagenes Erbe (Interface) (p. 173-175).
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 |
|---|---|---|---|
empty_override |
Empty override. |
None |
False |
reduced_visibility |
Override reduces visibility. |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.