추상화 클래스와 인터페이스는 객체 지향 프로그래밍에서 구조를 정의하는 방법으로 사용된다. 둘 다 계약(contract)을 정의하는데에 사용되지만 목적동작방식에 차이가 있다. 이에 대해 알아보자.

추상화 클래스 Abstract Class

공통 로직을 공유하면서도, 일부 메서드를 하위클래스에서 구현하도록 강제하고 싶을 때에 사용한다.

abstract class Animal {
    abstract makeSound():void;
}

class Dog extends Animal {
    makeSound():void {
        console.log("WooF!");
    }
}

const animal = new Animal();
//Error: Cannot create an instance of an abstract class.

인터페이스 Interface