Chapter 6. Implementing Interfaces

An interface defines a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. An interface defines a set of methods but does not implement them. A class that implements the interface agrees to implement all the methods defined in the interface, thereby agreeing to certain behavior.

Because an interface is simply a list of unimplemented methods you might wonder how an interface differs from an abstract class. The differences are significant:

  • An interface cannot implement any methods, whereas an abstract class can.

  • A class can implement many interfaces but can have only one superclass.

  • An interface is not part of the class hierarchy.

  • Unrelated classes can implement the same interface.

Let's look at C# interfaces more closely.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.89.2