Interfaces
An interface is the basic mechanism by which a COM component exposes functionality. You can think of an interface as a contract. It describes what a component is supposed to do. How it does it is left up to you as the creator of the interface, to a certain degree. One of the fundamentals of COM is the idea of separating the interface from the implementation.
For instance, Example 2.1 shows an interface created in Visual Basic called Animal.
Example 2-1. The Animal Interface
'Animal.cls
Private Enum Kingdoms
Mammal = 1
Reptile = 2
Insect = 3
Bird = 4
Fish = 5
End Enum
'Returns animal kingdom.
Private Function Kingdom( ) As Kingdoms
End Function
'Returns the name of an animal in a string.
Private Function Name( ) As String
End Function
'Returns the noise the animal makes in a string.
Private Function Noise( ) As String
End FunctionNotice that the functions in the class module
animal.cls are just empty stubs. C++ programmers
would recognize this as an abstract base class.
This serves only to describe what the Animal interface looks like. By
itself this does nothing. The interface must be
implemented before it becomes useful. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access