Push Down Field

A field is used only by some subclasses.

“A field is used only by some subclasses.”

Move it to the subclass.

graph LR
    A[Superclass::field] -->|Refactoring| B[Subclass A::field]

When to apply (Smells)

  • Refused Bequest: Superclass has a field quota but not all employees have quotas.

Motivation

  • Clarity: Only classes that need the data should have it.

Mechanics (Steps)

  1. Declare field in subclasses.
  2. Remove from superclass.

Explanation

Problem

Employee has quota, but Engineer doesn’t use quota.

Solution

Move quota to Salesman.

Pros and Cons

Pros Cons
  • Cleaner Superclass
  • Might introduce duplication if moved to multiple subclasses
  • Code example

    Typescript

    Before

    After

    PHP

    Before

    After