Chapter 9. Serialization and Persistence


In a component-oriented application, the component instances (the objects) maintain their state (the object's member variables) in memory and apply business logic on that state. But how is this state initially generated, and what happens to it when the application shuts down or when the user selects Save? In almost every application, object states aren't created out of thin air when the application starts. An application typically loads some file containing data and converts the information in the file into live objects. Similarly, when the application shuts down, the object state is saved (or, persisted) to a file. Traditionally, this is referred to as serialization and deserialization. These terms were originally coined to describe a simple binary dump of an object's state to a file and its subsequent recovery. In such cases, the application wrote the state of the object serially, one bit at a time. When the application later read the information, it processed the information serially in exactly the same order into a memory location and associated that location with an object.

Classic object-oriented programming didn't offer much in the way of implementing serialization. Consequently, not only did developers spend much of their valuable time on mundane serialization code instead of adding business value to their applications, but the resulting solutions were proprietary and singular. There was no generic way for two applications to share serialization files, because each used its own format, even if both applications ran on the same platform and used the same language, memory layout, word size, and so on.

With component-oriented applications, serialization is a critical issue. If an application contains several components from various vendors, how can it persist its objects into a single file without the individual components overwriting and destroying the information persisted there by other components?

.NET provides a standard, straightforward way to serialize and deserialize objects. Even though the .NET solution is trivial to use (in most cases, you aren't required to provide any explicit serialization code), it's also extensible, and you can provide your own serialization formats and implementations. .NET serialization is used not only to implement object persistence but also to facilitate the marshaling of objects and object references to remote clients.

This chapter describes the .NET types and tools for implementing serialization on both the server and client sides; shows how to provide custom serialization; and suggests solutions for dealing with special cases, such as the serialization of class hierarchies.



Programming. NET Components
Programming .NET Components, 2nd Edition
ISBN: 0596102070
EAN: 2147483647
Year: 2003
Pages: 145
Authors: Juval Lowy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net