Skip to content

Refused Bequest: Subclasses That Reject What They Inherit

How to spot subclasses that throw, no-op or zero out inherited methods, why it happens, and how to refactor toward honest hierarchies.

6 min readCode smellMisused abstractions

A subclass is supposed to be a more specific version of its parent. Refused Bequest is what you get when it isn't: the child inherits a set of methods and fields, then spends its body overriding them to throw, do nothing, or return a harmless zero. It took the inheritance for one or two convenient members and refused the rest. The problem is not the unused code. It is the lie in the type. Any caller holding a reference to the parent type assumes every inherited method works, and that assumption breaks the moment a refusing subclass shows up. In interviews this smell is the practical face of the Liskov Substitution Principle, and being able to point at a concrete override that breaks a caller is far more convincing than reciting the definition.

Signs

How to spot it in a review.

  • Overrides whose whole body is throw new Error("not supported") or its equivalent.
  • Overrides that are empty or return a neutral value like 0, null or an empty list just to satisfy the parent.
  • The subclass passes dummy values such as 0 or an epoch date to the parent constructor.
  • Callers check the concrete type with instanceof or isinstance before calling an inherited method.
  • The subclass uses one or two protected fields from the parent and none of its behaviour.

What it looks like

A typical case, in three languages.

class Subscription {
  constructor(
    public readonly customerId: string,
    protected monthlyPriceCents: number,
    protected seats: number,
    protected renewsOn: Date,
  ) {}

  renew(): Date {
    const next = new Date(this.renewsOn);
    next.setUTCDate(next.getUTCDate() + 30);
    this.renewsOn = next;
    return next;
  }

  pause(days: number): void {
    const resumed = new Date(this.renewsOn);
    resumed.setUTCDate(resumed.getUTCDate() + days);
    this.renewsOn = resumed;
  }

  changeSeats(newSeats: number, daysLeftInCycle: number): number {
    const delta = newSeats - this.seats;
    this.seats = newSeats;
    return Math.round((delta * this.monthlyPriceCents * daysLeftInCycle) / 30);
  }

  invoiceTotalCents(): number {
    return this.monthlyPriceCents * this.seats;
  }
}

class LifetimeLicense extends Subscription {
  constructor(customerId: string, seats: number) {
    super(customerId, 0, seats, new Date(0));
  }

  renew(): Date {
    throw new Error("Lifetime licenses do not renew");
  }

  pause(_days: number): void {
    // nothing to pause
  }

  changeSeats(newSeats: number, _daysLeftInCycle: number): number {
    this.seats = newSeats;
    return 0;
  }

  invoiceTotalCents(): number {
    return 0;
  }
}

const nightlyBatch: Subscription[] = [
  new Subscription("acme", 1200, 5, new Date("2024-06-01T00:00:00Z")),
  new LifetimeLicense("globex", 3),
];

for (const sub of nightlyBatch) {
  console.log(sub.customerId, sub.renew()); // throws on globex
}

LifetimeLicense was made a Subscription so it could reuse customerId and the seat count. Everything else is refused: renew throws, pause silently does nothing, changeSeats skips proration, and the constructor feeds the parent a zero price and an epoch date. The nightly renewal job, written against Subscription, crashes on the first lifetime customer. The only thing the two classes really share is a customer and a seat count, which belong in their own small type.

Why it happens

How code ends up like this.

  • A class was made a subclass to reuse a couple of fields or a helper method, not because it is a genuine specialisation of the parent.
  • The parent grew over time and accumulated behaviour that only some of its children need.
  • Requirements changed after the hierarchy was built, and a new variant was squeezed in under the nearest existing base class.
  • The language or framework made inheritance the easiest path to get a type accepted by existing code, so substitutability was never checked.

Treatment

The refactorings that cure it, and when to choose each.

Payoff

What you get once it's gone.

  • Code written against the base type works for every subtype, so batch jobs stop crashing on one odd record.
  • Each class's public surface matches what it can actually do, which makes the API easier to read and to test.
  • Dummy constructor arguments like zero prices and epoch dates disappear, removing a source of silent bugs.
  • New variants can be added by composing small pieces instead of fighting an oversized parent.

When to leave it

Sometimes it's not worth fixing.

  • The refused members are protected helpers that no outside caller ever reaches; the public contract is still fully honoured, so the cost is mostly cosmetic.
  • A framework base class forces you to inherit hooks you don't need, and leaving them as the framework's default no-ops is the documented way to use it.
  • The hierarchy is about to be deleted or rewritten, and untangling it now would be wasted effort.

Common questions

Short answers to the usual doubts.

How is Refused Bequest related to the Liskov Substitution Principle?

It is one of the most common ways LSP gets broken in real code. LSP says any subtype should be usable wherever its parent is expected without surprising the caller. A subclass that throws or silently skips inherited behaviour fails that test. In an interview, name the smell, then show the caller that breaks, like a renewal loop typed against the base class.

Is an empty override always Refused Bequest?

No. If the parent defines a hook whose documented default is to do nothing, and the child legitimately has nothing to do, an empty body honours the contract. The smell is when the parent's contract promises an effect, such as moving a renewal date, and the child quietly doesn't deliver it.

Should I just throw an exception for unsupported operations?

Throwing is more honest than a silent no-op, because the failure is visible. But it still means callers can't trust the base type and need defensive checks. Prefer restructuring so the unsupported method isn't on the shared type at all.

Why not fix it by adding a supportsRenewal() flag to the base class?

That pushes the type check into every caller and keeps the misleading method on the base. It also tends to multiply as new variants arrive. Splitting the contract so only renewable types expose renew lets the compiler or type hints enforce what the flag only suggests.

Does composition always beat inheritance here?

Not always. If the child uses most of what the parent offers and refuses one edge case, moving that one method down or reshaping its signature may be enough. Reach for composition when the child only wanted a few fields and rejects most of the behaviour, as in the lifetime license example.

Next guide3 of 4 · Smells: misused abstractionsTemporary Field: State That Only Lives During One Method CallRead the next one