Compartilhar via


When to Use Interfaces 

Interfaces are a powerful programming tool because they allow you to separate the definition of objects from their implementation. Interfaces and class inheritance each have advantages and disadvantages, and you may end up using a combination of both in your projects. This page and When to Use Inheritance will help you determine which approach is best for your situation.

Flexibility in Implementation

There are several other reasons why you might want to use interfaces instead of class inheritance:

  • Interfaces are better suited to situations in which your applications require many possibly unrelated object types to provide certain functionality.

  • Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfaces.

  • Interfaces are better in situations in which you do not need to inherit implementation from a base class.

  • Interfaces are useful in cases where you cannot use class inheritance. For example, structures cannot inherit from classes, but they can implement interfaces.

See Also

Tasks

How to: Create and Implement Interfaces
Walkthrough: Creating and Implementing Interfaces

Concepts

When to Use Inheritance
Interfaces Overview
Interface Definition
Implements Keyword and Implements Statement
Interface Implementation Examples in Visual Basic

Other Resources

Inheritance in Visual Basic