The Implements keyword is used to signify that a class member implements a specific interface.
An Implements statement requires a comma-separated list of interface members to be implemented. Generally, only a single interface member is specified, but you can specify multiple members. The specification of an interface member consists of the interface name, which must be specified in an implements statement within the class, a period, and the name of the member function, property or event to be implemented. The name of a member that implements an interface member can use any legal identifier, and is not limited to the InterfaceName_MethodName convention used in earlier versions of Visual Basic. For example, the following code fragment shows how to declare a subroutine named
Sub1 that implements a method of an interface:
Sub Sub1(ByVal i As Integer) Implements interfaceclass.interface2.Sub1
The parameter types and return types of the implementing member must match the interface property or member declaration in the interface. The most common way to implement an element of an interface is with a member that has the same name as the interface, as shown in the previous example.
To declare the implementation of an interface method, you can use any attributes that are legal on instance method declarations, including Overloads, Overrides, Overridable, Public, Private, Protected, Friend, Protected Friend, MustOverride, Default, and Static. The Shared attribute is not legal since it defines a class rather than an instance method.
Using Implements, you can also write a single method that implements multiple methods defined in an interface, as in the following example:
Protected Sub M1 Implements I1.M1, I1.M2, I2.M3, I2.M4
You can use a private member to implement a class member. When a private member implements a member of an interface, that member becomes available by way of the interface even though it is not available directly on object variables for the class.
Interfaces Overview | Interface Definition | Interface Implementation Examples | When To Use Interfaces | Creating and Implementing an Interface | Walkthrough: Creating and Implementing Interfaces | Inheritance | Implements Statement | Implements