Last Updated:

The .NET Framework class library | Programming based on interfaces.

The previous Serialize example uses the SoapFormatrer and FileStream classes. They are just two of the more than 2500 classes in the .NET Framework library. The .NET Framework library classes create the skeleton (infrastructure) of the application and provide the . NET applications. The following are just some of the features of the .NET Framework Class Library:

  • Base Class Library – contains basic functional features, such as strings, arrays and formatting elements;
  • transmission of network data;
  • security system;
  • remote processing;
  • diagnostics;
  • I/O;
  • databases;
  • XM L language;
  • Web services that enable you to use component interfaces anywhere on the Internet.
  • Web-programming;
  • User interface of the Windows operating system.

Programming based on interfaces

Suppose you want to encrypt your data, and therefore don't want to rely on serialization (conversion to sequential form) based on the Simple Object Access Protocol (SOAP) that is part of the .NET Framework library. Your class can inherit from the ISeriaiizable interface and contain an implementation of the corresponding algorithm (we will discuss how to do this in the following chapters). Then, when you save and restore data, the .NET Framework library will use your methods.

But how the .NET Framework library learns about this. that you implemented the 15-erializable interface? It turns out that it can query the metadata of the corresponding class in order to find out if it inherits the specified interface! Then, when you serialize an object or convert it from a sequential form to a "parallel" class library, the .NET Framework can use either its own algorithm or the code of the corresponding class.

Interface-based programming is used by .NET to use programmer-developed objects to supplement the standard functionality of the .NET Framework class library. The use of interfaces also allows you to bring work with different objects to a common denominator, without knowing the exact type of object. For example, formatters (such as the SOAP formatter used in this example) inherit the IFormatter interface. Programs can be written regardless of any particular (binary, SOAP) format used now, or a formatter that will be used in the future, and at the same time they will work properly.