Home Knowledge Base Refused Bequest

Refused Bequest is a code smell where a subclass inherits from a parent class but ignores, overrides without use, or throws exceptions for the majority of the inherited interface — indicating a broken inheritance relationship that violates the Liskov Substitution Principle (LSP), meaning objects of the subclass cannot safely be substituted wherever the parent is expected, which defeats the entire purpose of the inheritance relationship and creates brittle, misleading type hierarchies.

What Is Refused Bequest?

The smell manifests when a subclass rejects its inheritance:

Why Refused Bequest Matters

Root Causes

Accidental Hierarchy: The subclass was placed in the hierarchy for code reuse, not because there is a genuine is-a relationship. Square extends Rectangle was done to reuse rectangle methods, not because squares are fully substitutable rectangles.

Evolutionary Hierarchy: The parent's interface expanded over time. The subclass was created when the parent had 5 methods; now it has 20, and 15 are not applicable to the subclass.

Legacy Constraint: The hierarchy was inherited from an older design that made sense in a different context.

Refactoring Approaches

Composition over Inheritance (Most Recommended):

// Before: Bad inheritance
class ReadOnlyList extends ArrayList {
    public boolean add(E e) { throw new UnsupportedOperationException(); }
}

// After: Composition — use the list, do not claim to be one
class ReadOnlyList {
    private final List<E> delegate;
    public E get(int i) { return delegate.get(i); }
    public int size() { return delegate.size(); }
    // Only expose what ReadOnlyList actually supports
}

Extract Superclass / Pull Up Interface: Create a narrower shared interface that both classes can fully implement. ReadableList (with get, size, iterator) as the shared interface, with MutableList and ReadOnlyList as separate, non-related implementations.

Replace Inheritance with Delegation: The subclass keeps a reference to a parent-type object and delegates only the methods it wants to support, rather than inheriting the entire interface.

Tools

Refused Bequest is bad inheritance made visible — the code smell that exposes when a class hierarchy has been assembled for code reuse convenience rather than genuine behavioral substitutability, creating a type system that promises behavior it cannot deliver and forcing runtime defenses against what should be compile-time guarantees.

refused bequestcode ai

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.