Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- localStorage
- frontend
- SSE
- 성장기
- PostgreSQL
- 개발자
- 열공하자
- Lag
- ServerSentEvent
- node.js란
- node.js
- 실시간알림
- 파티셔닝
- Node.js기본
- partitioning
- Partition
- mariadb
- EventSource
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[TypeScript][ch6][Class] 추상 클래스(Abstract Classes) 본문
추상 클래스
- class 앞에 abstract 키워드 사용 > 완전하지 않은 class를 표현
- 정의만 있을 뿐, 몸체는 구현되어 있지 않음
- 몸체는 추상 클래스를 상속하는 클래스에서 해당 추상 메소드를 통해 구현함.
- (완전하지 않은 객체를 상속 기능을 이용해서 완전하게 만든 후 사용)
- abstract class는 완전하지 않은 Class이기 때문에 new를 이용해서 객체를 만들 수 없다.
abstract class AbstractPerson {
protected _name: string = 'Searchkim';
// abtract 키워드를 사용했기 때문에 메서드의 몸체를 구현하지 않음
// -> abtract 키워드를 사용하면 class 앞에 abstract를 붙여야 함
abstract setName(name: string): void;
}
// abstract class는 기능이 완전하지 않기 때문에 new 키워드 사용 불가
// new AbstractPerson(); // Error 발생
class Person11 extends AbstractPerson{
// 완전하지 않은 부모 클래스에서 구현되지 않은 메서드를 자식 클래스에서 구현
setName(name: string): void {
this._name = name;
}
}
const p11 = new Person11();
p11.setName('Anna');
'TypeScript 합시다' 카테고리의 다른 글
[TypeScript][ch7][Generic] Generic Basic (0) | 2022.02.18 |
---|---|
[TypeScript][ch7][Generic] Generic, Any와 다른 점 (0) | 2022.02.18 |
[TypeScript][ch6][Class] 상속(Inheritance) (0) | 2022.02.15 |
[TypeScript][ch6][Class] Singletons (0) | 2022.02.15 |
[TypeScript][ch6][Class] Static Properties & Methods (0) | 2022.02.15 |
Comments