추상형

위키백과, 우리 모두의 백과사전.
(추상 클래스에서 넘어옴)

추상형(abstract type, 애브스트랙트 타입)은 프로그래밍 언어에서 직접 인스턴스화시킬 수 없는 명목적 자료형 체계이다. 추상이 아닌 자료형, 즉 인스턴스화가 가능한 자료형은 구체형(concrete type, 콘크리트 타입)으로 부른다. 추상형은 실존주의형(existential type)으로 부른다.[1]

추상형은 어떠한 구현체(implementation)도 없거나 불완전한 구현체를 제공할 수 있다. 일부 언어에서 구현체가 없는 추상형은 프로토콜, 인터페이스, 시그니처, 클래스 타입으로 부른다. 클래스 기반 객체 지향 프로그래밍에서 추상형은 추상 클래스(abstract class, 즉 추상 베이스 클래스)로 구현되며 구체형은 구체 클래스(concrete class, 콘크리트 클래스)로 구현된다.

추상형의 표현[편집]

예시 (자바)[편집]

//By default, all methods in all classes are concrete, unless the abstract keyword is used.
abstract class Demo {
    // An abstract class may include abstract methods, which have no implementation.
    abstract public int sum(int x, int y);

    // An abstract class may also include concrete methods.
    public int product(int x, int y) { return x*y; }
}

//By default, all methods in all interfaces are abstract, unless the default keyword is used.
interface DemoInterface {
    [abstract] int getLength(); //Abstract can be used here, though is completely useless
    
    //The default keyword can be used in this context to specify a concrete method in an interface
    default int product(int x, int y) {
        return x * y;
    }
}

같이 보기[편집]

각주[편집]

  1. Mitchell, John C.; Plotkin, Gordon D.; Abstract Types Have Existential Type, ACM Transactions on Programming Languages and Systems, Vol. 10, No. 3, July 1988, pp. 470–502

외부 링크[편집]