Symmetry of Object Input and Output
The essence of object serialization is symmetry between output and input operations. This symmetry is provided by the various data stream classes for sequences of primitive types (int, float, string); but for a class, the symmetry must be provided by the input and output operations for that class.
For example, if the output operation for a class writes two int types followed by a float, and the input operation expects to read three int types, then incorrect data is read. In most cases, this kind of error halts processing and invalidates the stream.
The Serialization package solves this problem by using the same function for both object input and output. Each serializable class has a streamContents() member function (or global function for externally serializable classes) that is responsible for output and input of that class’s members.