Persistent Objects

We've seen that structured storage is necessary to allow multiple components to share the same disk file or other mass of storage. An object indicates its ability to save its persistent state to a storage or a stream element by implementing the interface IPersistStorage or IPersistStream (or a slight enhancement, IPersistStreamInit). There is also an IPersistFile interface for components that save to separate files. An object that implements any support whatsoever for saving and loading its state is called persistent. In Chapter 8, we'll deal with persistent objects in detail.

The client, or, more appropriately, container, that manages persistent objects creates or obtains the IStorage or IStream pointer to pass to the objects through IPersistStorage or IPersistStream[Init]. The container tells objects when to save or load their persistent states, so the container remains in control of the overall document or file but gives each component individual control over a storage or stream within that file. This tends to make structures within a file more intelligent by placing more of the code that knows how to handle the structures in objects rather than in the container.