interface 문

인터페이스의 이름과 인터페이스를 구성하는 속성 및 메서드를 선언합니다.

[modifiers] interface interfacename [implements baseinterfaces] {
   [interfacemembers]
}

인수

  • modifiers
    선택적 요소로서, 속성의 표시 유형 및 동작을 제어하는 한정자입니다.

  • interfacename
    필수적 요소로서, interface의 이름입니다. 표준 변수 명명 규칙을 따릅니다.

  • implements
    선택적 요소로서, 명명된 인터페이스가 이전에 정의된 인터페이스를 구현하거나 해당 인터페이스에 멤버를 추가함을 나타내는 키워드입니다. 이 키워드가 사용되지 않으면 표준 JScript 기본 인터페이스가 만들어집니다.

  • baseinterfaces
    선택적 요소로서, interfacename에 의해 구현되는 인터페이스 이름의 쉼표로 구분된 목록입니다.

  • interfacemembers
    선택적 요소로서, interfacemembers는 메서드 선언(function 문으로 정의됨) 또는 속성 선언(function getfunction set 문으로 정의됨)이 될 수 있습니다.

설명

JScript에서 interface 선언 구문은 class 선언 구문과 같습니다. 인터페이스는 모든 멤버가 abstractclass와 같으므로 함수 본문 없이 속성 및 메서드 선언만 포함할 수 있습니다. interface는 필드 선언, 이니셜라이저 선언 또는 중첩 클래스 선언을 포함할 수 없습니다. interface는 implements 키워드를 사용하여 하나 이상의 interfaces를 구현할 수 있습니다.

하나의 class는 하나의 기본 class만 확장할 수 있지만 여러 interfaces를 구현할 수 있습니다. 이와 같이 class 다음에 여러 interface를 구현하면 C++와 같은 다른 개체 지향 언어의 경우보다 간단한 다중 상속 형태를 사용할 수 있습니다.

예제

다음 코드에서는 하나의 구현이 여러 인터페이스에서 상속될 수 있는 방법을 보여 줍니다.

interface IFormA {
   function displayName();
}

// Interface IFormB shares a member name with IFormA.
interface IFormB {
   function displayName();
}

// Class CForm implements both interfaces, but only one implementation of
// the method displayName is given, so it is shared by both interfaces and
// the class itself.
class CForm implements IFormA, IFormB {
   function displayName() {
      print("This the form name.");
   }
}

// Three variables with different data types, all referencing the same class.
var c : CForm = new CForm();
var a : IFormA = c;
var b : IFormB = c;

// These do exactly the same thing.
a.displayName();
b.displayName();
c.displayName();

이 프로그램은 다음과 같이 출력됩니다.

This the form name.
This the form name.
This the form name.

요구 사항

.NET 버전

참고 항목

참조

class 문

function 문

function get 문

function set 문

기타 리소스

한정자