O'Reilly logo

Programming Visual Basic 2005 by Jesse Liberty

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

Implementing an Interface

Imagine that you are the author of a Document class. It turns out that Document objects can be stored in a database, so you decide to have Document implement the IStorable interface.

To do so, you must do two things:

  • Declare the class to implement the interface.

  • Implement each of the interface methods, events, properties, and so forth, and explicitly mark each as implementing the corresponding interface member.

To declare that the class implements the interface, you use the keyword Implements on the line below the class definition:

Public Class Document
    Implements IStorable

Visual Studio 2005 will help you with the available interfaces , as shown in Figure 18-7.

As soon as you write that your class implements the IStorable interface, Visual Studio 2005 will fill in all the required methods and properties of the interface, as shown in Figure 18-8!

IntelliSense helping find the interface

Figure 18-7. IntelliSense helping find the interface

IntelliSense stubs out all the interface methods and properties

Figure 18-8. IntelliSense stubs out all the interface methods and properties

All you have to do is fill in the stubbed out methods and properties and the Interface contract is fulfilled.

You cannot create an instance of an interface; instead you instantiate a class that implements the interface. The class implementing the interface must fulfill the contract exactly and completely. ...

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