Interfaces

In this lesson, another important topic of C# abstraction is covered, Interfaces.

What Is an Interface?

An interface is just like an abstract class but only specifies the behavior that a class must implement.

An interface can be used to achieve 100% abstraction as it can only contain abstract members(what is to be done) and no implementation details (how to be done) for these members. In this way, interfaces satisfy the definition of abstraction. The implementation details of the members declared in an interface are totally up to the classes implementing that interface.

An interface can be thought of as a contract that a class has to fulfill while implementing that interface. According to this contract, the class that implements an interface has to implement all the abstract members declared in that very interface.

Declaration

An interface is declared just like a class but using the interface keyword:

Get hands-on with 1200+ tech skills courses.