Note: This is a rough hack, nothing more.
Problem
How do you implement a persistance mechanism which is sufficiently robust and sufficiently generic?
Context
An object oriented application that requires the ability to persist object data.
Forces
and/or
Solution
Each persistence medium/container implements a "package" class. The package class is an Adaptor with a known interface that allows each component object to store data of any primitive data type supported by the implementation language (and optionally, certain non-primitive extensions such as strings) plus objects or object references.
On the transmit/write side, the component object which is to be persisted is passed a "write package" object, to which it writes whatever data it requires. The package object bundles the data up in whatever fashion is required by the persistence medium/container (including but not limited to things such as ASCII/binary format, endianism etc) and passes it on.
On the receive/read side, a "read package" object is created and given its data by the persistence media/container. A blank component object is created and passed the package object. The blank component object uses the the package to read and/or resolve its data attributes and object references. This process may include resolving differences in the current and stored versions of the class.