33

Pull Up Method


Goal

Methods that subclasses implement identically move to the shared superclass.

Before the refactoring
class Manager  extends Employee { name() { return this._name; } }
class Engineer extends Employee { name() { return this._name; } }
After the refactoring
class Employee { name() { return this._name; } }
class Manager  extends Employee {}
class Engineer extends Employee {}
Savings

One implementation, one place to fix; subclasses focus on what's actually different.

Note

If the methods only superficially resemble each other, pulling up creates a fake-shared abstraction — unify only when behavior is actually identical.