Push Down Method

Compare
Symptom
Human

A method on the parent class used by only one subclass — `Employee.quota()` used only by `Salesperson`.

Agent

A method declared on the parent that only one subclass overrides or invokes; the parent's interface includes a method that does not apply to most instances the agent reasons about.

Goal
Human

Methods used by only one subclass live with that subclass, not on the shared superclass.

Agent

The method lives on the subclass that uses it; reading the parent's interface returns only the methods every instance supports, dropping the irrelevant declaration from the agent's window.

Before the refactoring

class Employee {
quota() { /* used only by Salesperson */ }
}

After the refactoring

class Salesperson extends Employee {
quota() { /* ... */ }
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Every other subclass carries surface it doesn't use; readers can't tell which methods are shared and which are subclass-specific; the parent's true interface is muddied.

Agent

The parent's interface is muddied with subclass-specific methods; the agent can't tell which methods apply to which subclass without inspecting usage.

Tradeoff
Human

If the method is occasionally needed in the parent, pushing it down forces awkward type checks back at consumers — verify usage first.

Agent

If the parent occasionally consults the method for type checks or polymorphic dispatch, pushing it down forces awkward downcasts at every consumer the agent must verify.

Relief
Human

The superclass surface shrinks; subclasses that don't need the method aren't burdened by it.

Agent

The parent's interface shrinks by one method; queries about any subclass's behavior load fewer irrelevant declarations into the window, and code generated against the parent's interface no longer references a method most instances do not support.

Trap
Human

Pushing down methods used occasionally in the parent for type checks or polymorphic calls — forces awkward downcasts back at the parent's consumers.

Agent

Pushing down a method that callers reach through a parent-typed reference forces every such call site to downcast first; each downcast is a runtime type check the agent's generated code has to handle at every consumer.