Before | After |
---|---|
class Employee { ... }
class Salesman extends Employee {
private name: string;
}
class Engineer extends Employee {
private name: string;
} |
class Employee {
protected name: string;
}
class Salesman extends Employee { ... }
class Engineer extends Employee { ... } |
Inverse of: Push Down Field
When working with inheritance, sometimes we end up creating fields that seem particular to that subclass, but in fact was already added to another subclass in the hiearchy. This refactoring helps with these cases.
Since Javascript is a dynamic language, and because in dynamic languages fields are defined the first time they're assigned to, the process of pulling up a field is the same of pulling up a constructor's body.