Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-110

Inheritance tree of classes should not be too deep

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      This class has XX parents which is greater than YY authorized.
    • Highlighting:
      • Primary: The class name
      • Secondary: The class name of each parent class
        • message: Parent class.
    • List of parameters:
      Hide

      Key: max
      Description: Maximum depth of the inheritance tree. (Number)
      Default Value: 5
      Type: Integer

      Key: filteredClasses
      Description: Classes to be filtered out of the count of inheritance. Depth counting will stop when a filtered class is reached. Ex value: java.fwk.AbstractFwkClass, java.fwkPackage.*
      Default Value: ""
      Type: String

      Show
      Key: max Description: Maximum depth of the inheritance tree. (Number) Default Value: 5 Type: Integer Key: filteredClasses Description: Classes to be filtered out of the count of inheritance. Depth counting will stop when a filtered class is reached. Ex value: java.fwk.AbstractFwkClass, java.fwkPackage.* Default Value: "" Type: String
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      MaximumInheritanceDepth
    • Covered Languages:
      C#, C, C++, Java, Objective-C, PHP
    • Remediation Function:
      Linear with offset
    • Linear Argument Description:
      Number of parents above the defined threshold
    • Linear Factor:
      30mn
    • Linear Offset:
      4h
    • Analysis Level:
      Semantic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • FxCop:
      CA1501, AvoidExcessiveInheritance

      Description

      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.

      This rule raises an issue when the inheritance tree, starting from Object has a greater depth than is allowed.

        Attachments

          Issue Links

          1.
          C-Family RSPEC-3886 Language-Specification Active Unassigned
          2.
          C# RSPEC-3914 Language-Specification Active Unassigned
          3.
          Java RSPEC-5909 Language-Specification Active Unassigned
          4.
          PHP RSPEC-5942 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              freddy.mallet Freddy Mallet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated: