Finally, while you can use interfaces without members, the best practice is to use attributes
to indicate that types support a specific feature that doesn??™t actually require implementation.
On the other hand, interfaces with only one method are common, and several important .NET
Base Class Library (BCL) interfaces, including ICloneable, IComparable, IDisposable, and
IFormattable, have only a single method as a member.
What Can Be in an Interface?
Interfaces may have methods, properties, events, and nested types (interfaces, classes, and
structures) as members. Interfaces may inherit from one or more other interfaces. Here??™s an
example of some things you can declare in an interface:
Public Interface IMyDatabase
'Inherit from two other interfaces
Inherits IDisposable, ICloneable
'Method with no return type
Sub Insert(ByVal element As Object)
'Method with a return type
Function Retrieve(ByVal element As Object) As Object
'Property
Property Count() As Integer
'Event
Event DBEvent()
End Interface
In this example, IMyDatabase declares two methods, a property and an event, all of which
must be implemented by any type that implements the interface. It inherits IDisposable and
ICloneable. So, any type that implements IMyDatabase must also implement the Dispose
method of IDisposable and the Clone method of ICloneable.
Pages:
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191