Aracılığıyla paylaş


Implements Deyimi

Bir veya daha fazla arabirimleri veya sınıfta uygulanan arabirim üyeleri veya göründüğü yapı tanımı belirtir.

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

Bölümleri

  • interfacename
    Gerekli.Sınıf veya yapı içinde karşılık gelen üyeleri tarafından uygulanacak olan özellikler, yordamları ve olayları olan bir arabirimi.

  • interfacemember
    Gerekli.Uygulanmakta bir arabirim üyesi.

Notlar

Bir arabirim topluluğudur arabirim üyeleri (Özellikler, yordamları ve olaylar) temsil eden prototipler saklar.Bildirimleri yalnızca üyeler için arabirimler içerir; Bu üyeler, sınıflar ve yapılar uygular.Daha fazla bilgi için bkz. Arabirimler (Visual Basic).

Implements Deyimi hemen izleyin gerekir Class veya Structure ifadesi.

Bir arabirim geliştirdiğinizde, arabirimde bildirilen tüm üyeleri uygulamalıdır.Herhangi bir üye hariç tutma sözdizimi hatası olarak kabul edilir.Bağımsız bir üye uygulamak için belirttiğiniz Implements Tümcesi (Visual Basic) anahtar sözcüğü (ayrı olduğu Implements deyimi) yapı ya da sınıf üyesi bildirmek ne zaman.Daha fazla bilgi için bkz. Arabirimler (Visual Basic).

Sınıfları kullanarak Özel (Visual Basic) özellikleri ve yordamları, ancak bu üyeler uygulamaları yalnızca uygulama sınıfının bir örneği bir değişken olarak bildirilen arabirim türünde olması için çevrim erişilebilir.

Örnek

Aşağıdaki örnek, nasıl kullanılacağını gösterir Implements bir arabirim üyeleri uygulayan ifadesi.Adlı bir arabirim tanımlar ICustomerInfo bir olay, bir özellik ve bir yordam.Sınıf customerInfo arabiriminde tanımlanan tüm üyelerine uygular.

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

Unutmayın sınıfı customerInfo kullanan Implements deyimi sınıf üyeleri uygulayan belirtmek için ayrı kaynak kod satırında ICustomerInfo arabirimi.Sınıfındaki her üyenin kullandığı Implements bunu o arabirim üyesi uygulayan belirtmek için üye bildiriminde bir parçası olarak anahtar sözcük.

Aşağıdaki iki yordamdan önceki örnekte uygulanan arabirimi nasıl kullanabileceğinizi gösterir.Uygulama sınamak için aşağıdaki yordamları proje ve çağrı için ekleme testImplements yordam.

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

Ayrıca bkz.

Başvuru

Implements Tümcesi (Visual Basic)

Interface Deyimi (Visual Basic)

Diğer Kaynaklar

Arabirimler (Visual Basic)