Creating and implementing an interface
For many developers, interfaces are confusing and their purpose not clearly understood. Interfaces are actually quite easy to get to grips with once you understand the concept that defines an interface.
Interfaces act like verbs. So, for example, if we had to create two classes called Lion
and Tiger
that derive from the Cat
abstract class, the interface would describe some sort of action. Lions and tigers can roar (but not purr). We can then create an interface called IRoarable
. If we had to derive a class called Cheetah
from our abstract class Cat
, we would not be able to use the IRoarable
interface, because cheetahs purr. We would need to create an IPurrable
interface.
Getting ready
Creating an interface is ...
Get C# Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.