Serialization Package Architecture
The object streams in the Serialization package are based on the streams abstractions defined in the Streams package.
How Does Serialization Work?
Figure 20 shows how serialization typically works in a distributed application:
1. You stream an object to a portable format.
2. You pass the portable format between processes.
3. You have the receiving process stream the object from the portable format back into an instance of the original C++ class.
In this example, a client downloads data from a server. The portable format used is a compact object stream, which lets you reconstruct the serialized objects.
Both the server and the client maintain classes that encapsulate data and functionality. The original object’s data is transferred to the client and used to create a copy. In effect, the object is passed between processes by value. After the transfer, the sender and receiver side each own an object of that class.
Relationship to the Streams Package
The Streams package starts with byte streams or character streams, and then moves up to data streams. Object streams are the next level in the hierarchy above data streams. Many of these streams can be chained together to provide independent control at multiple levels of abstraction. Chaining is key to the Streams package architecture (see
“Streams Package Architecture.”)
Object streams follow the same pattern as the classes in the Streams package: the object streams interface is defined by a pair of handle classes,
RWObjectOutputStream and
RWObjectInputStream. Concrete implementation classes are derived from
RWObjectOutputStreamImp and
RWObjectInputStreamImp. These classes, in turn, are derived from
RWFilteredDataOutputStreamImp and
RWFilteredDataInputStreamImp, which allow object streams to be chained to data streams. Object streams also inherit all the primitive type operators from data streams.
Although the classes
RWObjectOutputStream and
RWObjectInputStream are part of the Serialization package, they are actually part of the Streams package architecture, as shown in
Figure 21 and
Figure 22. The relationship between the object streams and the Streams package is the same as the relationship between Java object streams and Java data streams.
Serialization class names are in bold type. The other classes are from the Streams package.
Serialization class names are in bold type. The other classes are from the Streams package.
Handle-Body Architecture
Like the Streams package, object streams use the handle-body pattern. This means that the classes
RWObjectOutputStream and
RWObjectInputStream, the handle classes, are intended to be used as-is. Object streaming behavior is extended and customized by deriving from the classes in the
RWObjectOutputStreamImp and
RWObjectInputStreamImp hierarchies, the body classes. Use of the handle-body pattern for streams means that they can be used as automatic variables (on the stack) and as instance variables without worrying about dynamic memory management.