SOLID & Design Patterns Interview Question #138

What is the Fragile Base Class problem?

Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios Senior Advanced

Quick Interview Answer

The Fragile Base Class problem occurs when changes to a base class unexpectedly break subclasses that depend on its behavior or implementation details. The risk grows with deep hierarchies and poorly defined extension points.

Detailed Explanation

The Fragile Base Class problem occurs when changes to a base class unexpectedly break subclasses that depend on its behavior or implementation details. The risk grows with deep hierarchies and poorly defined extension points.

Keep inheritance hierarchies shallow, define contracts clearly, and prefer composition when subclasses need extensive knowledge of base internals.

Code Example

public abstract class BaseProcessor
{
    // Changing the order or side effects of
    // protected virtual methods may break
    // subclasses unexpectedly.
}