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 very similar to creating an abstract class. The difference is that the interface is describing what the class can do, in the case of the Cheetah class, by implementing IPurrable.
How to do it…
- If you haven't already done so in the previous...