Implements 문

하나 이상의 인터페이스를 지정하거나, 해당 인터페이스가 있는 클래스 또는 구조체 정의에서 구현될 인터페이스 멤버를 지정합니다.

Implements interfacename [, ...]
-or-
Implements interfacename.interfacemember [, ...]

구성 요소

  • interfacename
    필수적 요소로서, 포함된 속성, 프로시저 및 이벤트가 클래스나 구조체의 해당 멤버에 의해 구현되는 인터페이스입니다.

  • interfacemember
    필수적 요소로서, 구현될 인터페이스의 멤버입니다.

설명

인터페이스는 포함된 멤버(속성, 프로시저, 이벤트)를 나타내는 프로토타입의 컬렉션입니다. 인터페이스에는 멤버에 대한 선언만 포함되어 있으며, 클래스와 구조체는 이 멤버를 구현합니다.

Implements 문이 Class 또는 Structure 문 바로 뒤에 있어야 합니다.

인터페이스를 구현하는 경우 해당 인터페이스에 선언된 모든 멤버를 구현해야 합니다. 멤버를 생략하면 구문 오류가 발생합니다. 개별 멤버를 구현하려면 클래스나 구조체에서 멤버를 선언할 때 Implements 절(Visual Basic) 키워드를 Implements 문과 별도로 지정합니다. 자세한 내용은 인터페이스(Visual Basic)을 참조하십시오.

클래스는 속성과 프로시저를 Private(Visual Basic)으로 구현할 수 있지만 구현하는 클래스의 인스턴스를 인터페이스의 형식으로 선언된 변수로 캐스팅해야 이들 멤버에 액세스할 수 있습니다.

예제

다음 예제에서는 Implements 문을 사용하여 인터페이스의 멤버를 구현하는 방법을 보여 줍니다. 또한 이벤트, 속성 및 프로시저를 사용하여 ICustomerInfo라는 인터페이스를 정의합니다. customerInfo 클래스는 인터페이스에 정의된 모든 멤버를 구현합니다.

Public Interface ICustomerInfo
    Event updateComplete()
    Property customerName() As String
    Sub updateCustomerStatus()
End Interface

Public Class customerInfo
    Implements ICustomerInfo
    ' Storage for the property value.
    Private customerNameValue As String
    Public Event updateComplete() Implements ICustomerInfo.updateComplete
    Public Property CustomerName() As String _
        Implements ICustomerInfo.customerName
        Get
            Return customerNameValue
        End Get
        Set(ByVal value As String)
            ' The value parameter is passed to the Set procedure
            ' when the contents of this property are modified.
            customerNameValue = value
        End Set
    End Property

    Public Sub updateCustomerStatus() _
        Implements ICustomerInfo.updateCustomerStatus
        ' Add code here to update the status of this account.
        ' Raise an event to indicate that this procedure is done.
        RaiseEvent updateComplete()
    End Sub
End Class

customerInfo 클래스는 개별 소스 코드 줄에서 Implements 문을 사용하여 ICustomerInfo 인터페이스의 모든 멤버를 구현하는 클래스를 나타냅니다. 그러면 클래스의 각 멤버는 멤버 선언 과정에서 Implements 키워드를 사용하여 해당 인터페이스 멤버를 구현함을 나타냅니다.

다음 두 프로시저는 이전 예제에서 구현된 인터페이스를 사용하는 방법을 보여 줍니다. 구현을 테스트하려면 해당 프로젝트에 이러한 프로시저를 추가하고 testImplements 프로시저를 호출합니다.

Public Sub testImplements()
    ' This procedure tests the interface implementation by
    ' creating an instance of the class that implements ICustomerInfo.
    Dim cust As ICustomerInfo = New customerInfo()
    ' Associate an event handler with the event that is raised by
    ' the cust object.
    AddHandler cust.updateComplete, AddressOf handleUpdateComplete
    ' Set the customerName Property
    cust.customerName = "Fred"
    ' Retrieve and display the customerName property.
    MsgBox("Customer name is: " & cust.customerName)
    ' Call the updateCustomerStatus procedure, which raises the
    ' updateComplete event.
    cust.updateCustomerStatus()
End Sub

Sub handleUpdateComplete()
    ' This is the event handler for the updateComplete event.
    MsgBox("Update is complete.")
End Sub

참고 항목

참조

Implements 절(Visual Basic)

Interface 문(Visual Basic)

기타 리소스

인터페이스(Visual Basic)