아래 내용은 리팩터링 2판 내용과 한달한권 읽기 강의를 기반하여 정리한 글입니다.
// 전
class Employee {...}
class Salesperson extends Employee {
get name() {...}
}
class Engineer extends Employee {
get name() {...}
}
//후
clas Employee {
get name() {...}
}
class Salesperson extends Employee {...}
class Engineer extends Employee {...}
// 전
class Employee {...}
class Salesperson extends Employee {
private String name;
}
class Engineer extends Employee {
private String name;
}
//후
clas Employee {
protected String name;
}
class Salesperson extends Employee {...}
class Engineer extends Employee {...}
// 전
class Party {...}
class Employee extends Party {
constructor(name, id, monthlyCost) {
super();
this._id = id;
this._name = name;
this._monthlyCost = monthlyCost;
}
}
//후
clas Party {
consturctor(name) {
this._name = name;
}
}
class Employee extends Party {
consturctor(name, id, monthlyCost) {
super(name);
this._id =id;
this._monthlyCost = monthlyCost;
}
}
//전
class Employee {
costructor(name) {...}
get isPriviledged() {..}
assignCar() {...}
}
class Manager {
constructor(name, grade) {
super(name);
this._grade = grade;
if( this.isPrivileged) this.assignCar(); // 중복되는 공통 작업
}
get isPrivileged() {
return this._grade > 4;
}
}
//후
class Employee {
costructor(name) {...}
get isPriviledged() {..}
assignCar() {...}
finishConstruction() {
if(this.isPriviledged) this.assignCar();
}
}
class Manager {
constructor(name, grade) {
super(name);
this._grade = grade;
this.finishConstruction(); // 공통 코드 호출로 변경
}
}
//전
class Employee {
get quota {...}
}
class Engineer extends Employee {...}
class Salesperson extends Employee {...}
//후
class Employee {...}
class Engineer extends Employee {...}
class Salesperson extends Employee {
get quota{...}
}
//전
class Employee {
private String quota;
}
class Engineer extends Employee {...}
class Salesperson extends Employee {...}
//후
class Employee {...}
class Engineer extends Employee {...}
class Salesperson extends Employee {
private String quota;
}
//전
function createEmployee(name, type) {
return new Employee(name, type);
}
//후
function createEmployee(name, type) {
switch (type) {
case "engineer" : return new Engineer(name);
case "salesperson" : return new Salesperson(anem);
case "manager" : reutrn new Manager(name);
}
}
//전
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._genederCode;}
}
\\전
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 Salesperson extends Employee {...}
\\후
class Employee {...}
\\전
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.dyasToShip
: this._warehouse.daysToShip;
}
}
class PriorityOrderDelegate {
get daysToShip() {
return this._priorityPlan.daysToShip;
}
}
\\전
class List {...}
class Stack extends List {...}
\\후
class Stack {
constructor() {
this._storage = new List();
}
}
class List{..}
한달한권 리팩터링 강의 구매 고민 중인데 혹시 만족하시나요?