다음을 통해 공유


구현문

표시되는 클래스 또는 구조 정의에서 구현해야 하는 하나 이상의 인터페이스 또는 인터페이스 멤버를 지정합니다.

문법

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

부분

interfacename
필수 사항입니다. 클래스 또는 구조의 해당 멤버가 속성, 프로시저 및 이벤트를 구현해야 하는 인터페이스입니다.

interfacemember
필수 사항입니다. 구현되는 인터페이스의 멤버입니다.

비고

인터페이스는 인터페이스가 캡슐화하는 멤버(속성, 프로시저 및 이벤트)를 나타내는 프로토타입의 컬렉션입니다. 인터페이스에는 멤버에 대한 선언만 포함됩니다. 클래스 및 구조체는 이러한 멤버를 구현합니다. 자세한 내용은 인터페이스를 참조하세요.

문은 Implements 즉시 or Structure 문을 따라 Class 야 합니다.

인터페이스를 구현할 때 인터페이스에 선언된 모든 멤버를 구현해야 합니다. 멤버를 생략하는 것은 구문 오류로 간주됩니다. 개별 멤버를 구현하려면 클래스 또는 구조체에서 멤버를 선언할 때 Implements 키워드(문과 Implements 별개)를 지정합니다. 자세한 내용은 인터페이스를 참조하세요.

클래스는 속성 및 프로시저의 Private 구현을 사용할 수 있지만 이러한 멤버는 구현 클래스의 인스턴스를 인터페이스 형식으로 선언된 변수로 캐스팅해야만 액세스할 수 있습니다.

예제 1

다음 예제에서는 문을 사용하여 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 해당 멤버 선언의 일부로 키워드를 사용하여 해당 인터페이스 멤버를 구현함을 나타냅니다.

예제 2

다음 두 절차에서는 앞의 예제에서 구현된 인터페이스를 사용하는 방법을 보여 줍니다. 구현을 테스트하려면 이러한 프로시저를 프로젝트에 추가하고 프로시저를 호출합니다 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

참고하십시오