인터페이스 구현 : implement
클래스 상속 : extends
데코레이터 : 클래스의 정보를 수정할 수 있게함
서버 코드 맨 첨에 실행시키면 터미널창에 뜨는 실행문들
interface Person {
firstName : string;
lastName : string;
}
interface Notebook {
model : string;
isMacbook : boolean;
whenOpened(): void;
}
class Developer implements Person {
firstName: string;
lastName: string;
notebook!: Notebook;
constructor() {
this.firstName = "Gawon";
this.lastName = 'Seo';
}
}
//!: 로 해도 생성자에서 초기화할 수 있음, 나중에 인스턴스를 생성할 때 값을 초기화해주면 됨
/*class YoungChan extends Developer {
constructor() {
super(); //상속받을 클래스의 정보를 가져오기 위해 super 사용
this.firstName = 'YoungChan';
this.notebook = new Macbook(); // 의존성 : Mackbook 클래스의 개체를 생성 후 영찬 클래스에 넣어줌
}
}*/
class YoungChan extends Developer {
constructor(notebook: Notebook) {
super(); //상속받을 클래스의 정보를 가져오기 위해 super 사용
this.firstName = 'YoungChan';
this.notebook = notebook; // 의존성 : Mackbook 클래스의 개체를 생성 후 영찬 클래스에 넣어줌
}
}
class Macbook implements Notebook {
model = 'Macbook';
isMacbook = true;
whenOpened() {
console.log('boom');
}
}
class Gram implements Notebook {
model !: string;
isMacbook!: boolean;
constructor() {
this.isMacbook = false;
}
whenOpened() {
console.log('고장');
}
}
const macbook = new Macbook();
const gram = new Gram();
const developer = new YoungChan(new Macbook());
developer.notebook.whenOpened();
console.log(developer)
controller -> 서비스 -> repository -> db
순으로 의존성 있음
비동기가 일어날 때 : 디스크에서 쓰기,읽기가 동시에 일어날 때 , http에서 다른 api요청?
비동기로 작동하는 메소드엔 앞에 async를 붙이고, 리턴 타입에 promise로 한 번 감싸줌
데이터 뽑아내려면 await를 붙여서 동기처럼 만들어서 사용함