Interfaces in C#

Interfaces in C#: Interface Definition, User Interfaces, Software Interfaces, Solving Multiple Inheritance, Defining Interfaces, Polymorphism with Interfaces.

Updated

  1. Interface Definition (Apprentice): The word "interface" is both a noun and a verb, and software uses both meanings.
  2. User Interfaces (Novice): A smart home's thermostat, wall panel, phone app and voice assistant show how many user interfaces can control the same software.
  3. Software Interfaces (Apprentice): A software interface is a contract between pieces of code. It lists what a class can do, never how, so code can use any class that keeps the contract. .NET is full of them, such as IEnumerable<T>.
  4. Solving Multiple Inheritance (Journeyman): A C# class can have only one base class, which avoids the confusion of inheriting two versions of the same method. Instead, it can implement as many interfaces as it needs, since an interface brings a contract, not code.
  5. Defining Interfaces (Journeyman): Define an interface with the interface keyword, a name starting with I, and members with no bodies. A class implements it by listing it after the colon, after its base class, and writing every member as public.
  6. Polymorphism with Interfaces (Freelancer): An interface can be a variable's, parameter's or list's type, so it can hold objects of unrelated classes that keep the same contract. Depending on an interface, such as IClock, lets a test pass any fake that implements it.