O'Reilly logo

VB Shell Programming by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 Function

Notice 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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required