Replace Superclass with Delegate

Symptom

A subclass that overrides parent methods to no-ops or 'unsupported'; the agent reasoning about polymorphic calls on parent-typed references cannot trust the contract.

Goal

The former subclass holds a delegate of the former parent's role; the agent reads the new class's interface as the contract instead of loading the former parent to filter out methods the subclass refused.

Before the refactoring

class CategoryItem extends Scroll {
// uses some Scroll methods, refuses others
}

After the refactoring

class CategoryItem {
constructor() { this.scroll = new Scroll(); }
date() { return this.scroll.date(); }
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Liskov violations break the agent's polymorphic reasoning; the agent must defensively check at every call site whether the subclass honors the parent's contract.

Tradeoff

Composition adds a forwarding method on the former subclass for every parent method exposed; the agent loses syntactic polymorphism and pays ceremony for explicit delegation.

Relief

References typed against the former subclass hold only the methods the class actually implements; generated code that calls a method on a reference no longer dispatches through inherited methods the subclass overrode to no-op or unsupported.

Trap

Replacing inheritance with delegation on hierarchies where the subclass uses every inherited method adds a forwarding method per parent method without changing what the agent's generated calls do.