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 Party {}
class Employee extends Party {
constructor(name, id, monthlyCost) {
super();
this._id = id;
this._name = name;
this._monthlyCost = monthlyCost;
}
// 생략
}
class Department extends Party {
constructor(name, staff) {
super();
this._name = name;
this._staff = staff;
}
// 생략
}
class Party {
constructor(name) {
this.name = name;
}
}
class Employee extends Party {
constructor(name, id, monthlyCost) {
super(name);
this._id = id;
this._monthlyCost = monthlyCost;
}
// 생략
}
class Department extends Party {
constructor(name, staff) {
super(name);
this._staff = staff;
}
// 생략
}