Skip to Content
Programming Visual Basic .NET, Second Edition
book

Programming Visual Basic .NET, Second Edition

by Jesse Liberty
April 2003
Intermediate to advanced
560 pages
14h 4m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET, Second Edition

Chapter 8. Interfaces

An interface is a contract that guarantees to a client how a class or structure will behave. When a class implements an interface, it tells any potential client “I guarantee I’ll support the methods, properties, events, and indexers of the named interface.” (See Chapter 5 for information about methods and properties, see Chapter 12 for information about events, and see Chapter 9 for coverage of indexers.)

An interface offers an alternative to a MustInherit class (see Chapter 6) for creating contracts among classes and their clients. These contracts are made manifest using the Interface keyword, which declares a reference type that encapsulates the contract.

Syntactically, an interface is like a class that has only MustInherit methods. A MustInherit class serves as the base class for a family of derived classes, while interfaces are meant to be mixed in with other inheritance trees.

When a class implements an interface, it must implement all the methods of that interface; in effect the class says “I agree to fulfill the contract defined by this interface.”

Inheriting from a MustInherit class implements the is-a relationship, introduced in Chapter 4. Implementing an interface defines a different relationship that we’ve not seen until now: the implements relationship. These two relationships are subtly different. A car is a vehicle, but it might implement the CanBeBoughtWithABigLoan capability (as can a house, for example).

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.
Start your free trial

You might also like

Programming Visual Basic .NET

Programming Visual Basic .NET

Dave Grundgeiger
VB.NET Language in a Nutshell, Second Edition

VB.NET Language in a Nutshell, Second Edition

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596004389Supplemental ContentCatalog PageErrata