Interfaces

An interface, similar to an abstract class, supports interface-based inheritance. Interfaces are declarations for an abstract reference type. Another way to think about interfaces is to consider them to be contracts between the class that implements them and the calling class.

Declaring an Interface

Interfaces can inherit from one or more base interfaces but can't have any access to modifiers or security attributes associated with them. Listing A.25 shows the declaration of a simple interface.

Listing A.25. A Simple Interface
using System;

interface IPerson{

   String Name{
      get;
      set;
   }

   int Age{
      get;
      set;
   }
}

This example shows the simple IPerson interface that requires Name and Age properties to be implemented. Notice that the get ...

Get Building e-Commerce Sites with the .NET Framework 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.