Class Interfaces in C#
A class interface is like a kind of contract. If a class implements an interface, it means that it—and any derived
classes that inherit from the initial class—must have implementations for the members whose signatures are included
in the implementation specification. This means that if you know that a class implements an interface, you know that
it implements certain members, and you know what to expect about how those members work—at least in terms of method
signatures and member type. (There is, of course, nothing to stop someone from implementing a method specified by
an interface as a stub. A method written this way meets the contract specified by the interface—but doesn’t actually
do anything.)
In this first part of this article, we’ll take a closer look at class interfaces. How do they compare with abstract
base classes, and when should they be used? You'll learn about inspecting a class interface with the Object Browser.
Next, what are some of the most important .NET interfaces? Finally,
I’ll show you how to create a class that implements the IComparable interface. (As I’ll explain further, implementing
IComparable means that the class must contain a comparison method for ordering objects based on the class.)
In the second part of this article, I’ll show you how to create and implement your own custom class interface.
|
|
Search Engine Optimization
 
Syndication Viewer
Our Web host:
IX WebHosting
|