Search code examples
.netinheritancecompatibility

Is inheriting a new base class (that inherits the old base class) a breaking change?


I have class LegacyClass which inherits OldBaseClass.

I'm considering a change to introduce a new class in between so that

LegacyClass inherits NewBaseClass AND NewBaseClass inherits OldBaseClass.

Neither NewBaseClass nor OldBaseClass is abstract. Will this change break assembly compatibility for old MSIL assemblies that depend on (and maybe even inherit) LegacyClass?


Solution

  • As stated in this answer, it should be ok, as long as you don't actually change any of the existing behaviour (and more specifically, depending on how that behaviour is changed). If all that the new class does is add new (separate) methods / properties, then you should be fine. However, as is usually the case, it depends. Consider the following questions:

    • Who is using your assembly (Outsiders or only those within your organisation)?
    • Are you able to recompile the clients?
    • Are you able to run automated or manual unit tests on those clients?
    • Are you aiming to add or change functionality of your LegacyClass?