2.20.1 추상 클래스
implements보다 조금 더 구체적으로 클래스의 모양을 정의하는 방법이 있습니다. 추상 클래스(abstract class)입니다.
abstract class AbstractPerson {
name: string;
age: number;
married: boolean = false;
abstract value: number;
constructor(name: string, age: number, married: boolean) {
this.name = name;
this.age = age;
this.married = married;
}
sayName() {
console.log(this.name);
}
abstract sayAge(): void;
abstract sayMarried(): void;
}
class RealPerson extends AbstractPerson {
sayAge() {
console.log(this.age);
}
}
// Non-abstract class 'RealPerson' does not implement inherited abstract member 'sayMarried' from class 'AbstractPerson'. Non-abstract class 'RealPerson' does not implement inherited abstract member 'value' from class 'AbstractPerson'.