Push Down Field

Compare
Symptom
Human

A field on the parent class used by only one subclass — `Employee.quota` used only by `Salesperson`, ignored by everyone else.

Agent

A field declared on the parent that only one subclass reads or writes; the parent's stored state includes a slot that does not apply to most instances the agent reasons about.

Goal
Human

A field used by only one subclass moves out of the parent and into that subclass.

Agent

The field lives on the subclass that uses it; the parent's storage declaration carries only the fields every instance holds, dropping the irrelevant declaration from the agent's window.

Before the refactoring

class Employee {
quota; // only Salesperson uses this
}

After the refactoring

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

Every instance carries storage it doesn't use; readers can't tell from the parent's shape which fields apply; serialization carries dead weight.

Agent

The parent's storage carries dead weight; serialization includes ignored fields; the agent's reasoning about the parent's shape is muddied.

Tradeoff
Human

If the field is occasionally consulted in the parent for type checks, pushing it down forces awkward downcasts — verify usage first.

Agent

If the parent occasionally consults the field for type checks, pushing it down forces awkward downcasts the agent must add and verify at every consumer.

Relief
Human

Other subclasses no longer carry storage they ignore; the parent's surface shrinks; the field's meaning becomes local.

Agent

Other subclasses no longer carry storage they never touch; queries about the parent or any sibling subclass load fewer irrelevant field declarations into the window.

Trap
Human

Pushing down fields the parent occasionally consults for type checks or polymorphic dispatch — forces awkward downcasts at the parent's consumers.

Agent

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