rspec/rules/S110/java/rule.adoc

19 lines
1.1 KiB
Plaintext
Raw Normal View History

Inheritance is certainly one of the most valuable concepts in object-oriented programming. It's a way to compartmentalize and reuse code by creating collections of attributes and behaviors called classes which can be based on previously created classes. But abusing this concept by creating a deep inheritance tree can lead to very complex and unmaintainable source code. Most of the time a too deep inheritance tree is due to bad object oriented design which has led to systematically use 'inheritance' when for instance 'composition' would suit better.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue when the inheritance tree, starting from ``++Object++`` has a greater depth than is allowed.
2021-02-02 15:02:10 +01:00
For the parameter of the rule, the following rules are applied:
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
* ``++?++`` matches a single character
* ``++*++`` matches zero or more characters
* ``++**++`` matches zero or more packages
Examples:
2021-01-27 13:42:22 +01:00
* ``++java.fwk.AbstractFwkClass++`` will stop count when AbstractFwkClassclass is reached.
* ``++java.fwkPackage.*++`` will stop count when any member of java.internal package is reached.
* ``++java.fwkPackage.**++`` same as above, but including sub-packages.