Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Interfaces

The System namespace defines a number of interfaces. An interface is a set of pure virtual function definitions, which a class can choose to implement. You define an interface to enforce a common design pattern among classes that are not hierarchically related. For example, the IDisposable interface contains the method Dispose, used for deterministic finalization. This provides a way to force an object to perform its cleanup code immediately instead of when the garbage collector feels like getting around to it. Any class anywhere in any inheritance hierarchy might reasonably need this behavior. However, most classes won't need this behavior, so it wouldn't make sense to put it in the System.Object base class and force all objects to implement it whether they needed it or not. Instead, a class that needs this behavior implements the interface, ensuring that it follows the same syntactic rules as all other objects that do so, without disturbing its inheritance relationships with its base classes. The interfaces in Table 3 were felt to be common enough to occupy the System namespace. Many other subordinate namespaces also define more specialized interfaces.

Table 3.

Interface

Meaning

IAsyncResult

Represents the status of an asynchronous operation.

ICloneable

Supports cloning, which creates a new instance of a class with the same value as an existing instance.

IComparable

Defines a generalized comparison method that a value type or class implements to create a type-specific comparison method.

IDisposable

Defines a method to release allocated unmanaged resources.

IFormatProvider

Provides a mechanism for retrieving an object to control formatting.

IFormattable

Provides functionality to format the value of an object into a string representation.

  • + Share This
  • 🔖 Save To Your Account