
Change Function Declaration)class Employee {...}
class Salesman extends Employee {
get name() {...}
}
class Engineer extends Employee {
get name() {...}
}class Employee {
get name() {...}
}
class Salesman extends Employee {...}
class Engineer extends Employee {...}Rename Field)protected 로 선언하면 된다.class Employee {...} // Java
class Salesman extends Employee {
private String name;
}
class Engineer extends Employee {
private String name;
}class Employee {
protected String name;
}
class Salesman extends Employee {...}
class Engineer extends Employee {...}super() 호출 직후로 옮긴다. (Slide Statements)super() 로 건넨다.함수 추출하기와 메서드 올리기를 차례로 적용한다.class Party {...}
class Employee extends Party {
constructor(name, id, monthlyCost) {
super();
this._id = id;
this._name = name;
this._monthlyCost = monthlyCost;
}
}class Party {
constructor(name){
this._name = name;
}
}
class Employee extends Party {
constructor(name, id, monthlyCost) {
super(name);
this._id = id;
this._monthlyCost = monthlyCost;
}
}class Employee {
get quota {...}
}
class Engineer extends Employee {...}
class Salesman extends Employee {...}class Employee {...}
class Engineer extends Employee {...}
class Salesman extends Employee {
get quota {...}
}class Employee { // Java
private String quota;
}
class Engineer extends Employee {...}
class Salesman extends Employee {...}class Employee {...}
class Engineer extends Employee {...}
class Salesman extends Employee {
protected String quota;
}Replace Type Code with Subclasses
function createEmployee(name, type) {
return new Employee(name, type);
}function createEmployee(name, type) {
switch (type) {
case "engineer": return new Engineer(name);
case "salesman": return new Salesman(name);
case "manager": return new Manager (name);
}Replace Constructor with Factory Function)함수 추출하기와 함수 옮기기를 차례로 적용하여 슈퍼클래스로 옮긴다.class Person {
get genderCode() {return "X";}
}
class Male extends Person {
get genderCode() {return "M";}
}
class Female extends Person {
get genderCode() {return "F";}
}class Person {
get genderCode() {return this._genderCode;}
}중복 동작을 상속으로 해결하느냐 위임으로 해결하느냐에 달렸다.생성자 본문 올리기, 메서드 올리기, 필드 올리기를 차례로 적용하여 공통 원소를 슈퍼클래스로 옮긴다.함수로 추출한 다음 메서드 올리기를 적용한다.class Department {
get totalAnnualCost() {...}
get name() {...}
get headCount() {...}
}
class Employee {
get annualCost() {...}
get name() {...}
get id() {...}
}class Party {
get name() {...}
get annualCost() {...}
}
class Department extends Party {
get annualCost() {...}
get headCount() {...}
}
class Employee extends Party {
get annualCost() {...}
get id() {...}
}필드 올리기와 메서드 올리기 혹은 필드 내리기와 메서드 내리기를 적용하여 모든 요소를 하나의 클래스로 옮긴다.class Employee {...}
class Salesman extends Employee {...}class Employee {...}Replace Subclass with Delegate
Replace Constructor with Factory Function)함수 옮기기를 적용해 위임 클래스로 옮긴다. 원래 메서드에서 위임하는 코드는 지우지 않는다.Remove Dead Code)class Order {
get daysToShip() {
return this._warehouse.daysToShip;
}
}
class PriorityOrder extends Order {
get daysToShip() {
return this._priorityPlan.daysToShip;
}
}class Order {
get daysToShip() {
return (this._priorityDelegate)
? this._priorityDelegate.daysToShip
: this._warehouse.daysToShip;
}
}
class PriorityOrderDelegate {
get daysToShip() {
return this._priorityPlan.daysToShip
}
}Replace Superclass with Delegate
class List {...}
class Stack extends List {...}class Stack {
constructor() {
this._storage = new List();
}
}
class List {...}