Implements ステートメントImplements Statement
表示されるクラスまたは構造体の定義に実装する必要がある1つ以上のインターフェイス、またはインターフェイスメンバーを指定します。Specifies one or more interfaces, or interface members, that must be implemented in the class or structure definition in which it appears.
構文Syntax
Implements interfacename [, ...]
' -or-
Implements interfacename.interfacemember [, ...]
指定項目Parts
interfacename
必須。Required. クラスまたは構造体の対応するメンバーによって実装されるプロパティ、プロシージャ、およびイベントを持つインターフェイス。An interface whose properties, procedures, and events are to be implemented by corresponding members in the class or structure.
interfacemember
必須。Required. 実装されているインターフェイスのメンバー。The member of an interface that is being implemented.
コメントRemarks
インターフェイスは、インターフェイスによってカプセル化されるメンバー (プロパティ、プロシージャ、およびイベント) を表すプロトタイプのコレクションです。An interface is a collection of prototypes representing the members (properties, procedures, and events) the interface encapsulates. インターフェイスには、メンバーの宣言のみが含まれます。クラスと構造体は、これらのメンバーを実装します。Interfaces contain only the declarations for members; classes and structures implement these members. 詳細については、「 インターフェイスで定義されているインターフェイスのプライベート C++ 固有の実装です。For more information, see Interfaces.
Implements
ステートメントは、Class
または Structure
ステートメントの直後に記述する必要があります。The Implements
statement must immediately follow the Class
or Structure
statement.
インターフェイスを実装する場合は、インターフェイスで宣言されたすべてのメンバーを実装する必要があります。When you implement an interface, you must implement all the members declared in the interface. メンバーを省略すると、構文エラーと見なされます。Omitting any member is considered to be a syntax error. 個々のメンバーを実装するには、クラスまたは構造体でメンバーを宣言するときに、 Implementsキーワード (Implements
ステートメントとは別のもの) を指定します。To implement an individual member, you specify the Implements keyword (which is separate from the Implements
statement) when you declare the member in the class or structure. 詳細については、「 インターフェイスで定義されているインターフェイスのプライベート C++ 固有の実装です。For more information, see Interfaces.
クラスでは、プロパティとプロシージャのプライベート実装を使用できますが、これらのメンバーには、インターフェイスの型として宣言された変数に、実装するクラスのインスタンスをキャストすることによってのみアクセスできます。Classes can use Private implementations of properties and procedures, but these members are accessible only by casting an instance of the implementing class into a variable declared to be of the type of the interface.
例Example
次の例は、Implements
ステートメントを使用してインターフェイスのメンバーを実装する方法を示しています。The following example shows how to use the Implements
statement to implement members of an interface. これは、イベント、プロパティ、およびプロシージャを使用して ICustomerInfo
という名前のインターフェイスを定義します。It defines an interface named ICustomerInfo
with an event, a property, and a procedure. クラス customerInfo
、インターフェイスで定義されているすべてのメンバーを実装します。The class customerInfo
implements all the members defined in the interface.
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
は、クラスが ICustomerInfo
インターフェイスのすべてのメンバーを実装していることを示すために、別のソースコード行で Implements
ステートメントを使用することに注意してください。Note that the class customerInfo
uses the Implements
statement on a separate source code line to indicate that the class implements all the members of the ICustomerInfo
interface. 次に、クラスの各メンバーは、メンバー宣言の一部として Implements
キーワードを使用して、そのインターフェイスメンバーを実装していることを示します。Then each member in the class uses the Implements
keyword as part of its member declaration to indicate that it implements that interface member.
例Example
次の2つの手順は、前の例で実装されたインターフェイスを使用する方法を示しています。The following two procedures show how you could use the interface implemented in the preceding example. 実装をテストするには、これらのプロシージャをプロジェクトに追加し、testImplements
プロシージャを呼び出します。To test the implementation, add these procedures to your project and call the testImplements
procedure.
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
参照See also
フィードバック
フィードバックを読み込んでいます...