Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Development Edition
 Avoid excessive inheritance

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio Team System
Avoid excessive inheritance

TypeName

AvoidExcessiveInheritance

CheckId

CA1501

Category

Microsoft.Maintainability

Breaking Change

Breaking

A type is more than four levels deep in its inheritance hierarchy.

Deeply nested type hierarchies can be difficult to follow, understand, and maintain. This rule limits analysis to hierarchies within the same module.

To fix a violation of this rule, derive the type from a base type less deep in the inheritance hierarchy or eliminate some of the intermediate base types.

It is safe to suppress a warning from this rule; however, the code might be more difficult to maintain. Note that depending on the visibility of base types, resolving violations of this rule might create breaking changes. For example, removing public base types is a breaking change.

The following example shows a type that violates the rule.

Visual Basic
Imports System

Namespace MaintainabilityLibrary

   Class BaseClass
   End Class

   Class FirstDerivedClass
      Inherits BaseClass
   End Class

   Class SecondDerivedClass
      Inherits FirstDerivedClass
   End Class

   Class ThirdDerivedClass
      Inherits SecondDerivedClass
   End Class

   Class FourthDerivedClass
      Inherits ThirdDerivedClass
   End Class

   ' This class violates the rule.
   Class FifthDerivedClass
      Inherits FourthDerivedClass
   End Class

End Namespace

C#
using System;

namespace MaintainabilityLibrary
{
   class BaseClass {}
   class FirstDerivedClass : BaseClass {}
   class SecondDerivedClass : FirstDerivedClass {}
   class ThirdDerivedClass : SecondDerivedClass {}
   class FourthDerivedClass : ThirdDerivedClass {}

   // This class violates the rule.
   class FifthDerivedClass : FourthDerivedClass {}
}

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker