Interfaces

Recall the Shape class from the drawing program case study presented earlier. It contained the abstract method DrawYourself, which obliged any class derived from Shape to implement a DrawYourself method with the same signature and return type. In other words any class derived from Shape had to fulfill a contract saying: “I the derived class of Shape hereby promise to implement any abstract method contained in Shape or I shall be abstract myself”. This guarantee enabled us to call the different DrawYourself implementations in Circle, Triangle and Rectangle through dynamic binding. Notice that the Shape class didn't contain any data members or function member implementations and therefore didn't offer any code reuse benefits to its sub ...

Get C# Primer Plus 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.