An object in its internal form may consist of just simple data types, for example, a TPoint, which just has two TInt values representing its X and Y co-ordinates, or a network of objects, for example, a CBufSeg. There are two ways of storing the external form of the object:
When externalizing an object to a stream, the stream is passed to the the ExternalizeL() function and, in general, an object has no knowledge of where, in the stream, the data is written.
When a whole network of objects is to be externalised it is useful to store an object in its own stream network. This is particularly important if other objects are to be restored without restoring this one. The main reason is that it is very difficult to read past an object's data in a single stream without knowing something about its internal form.
You should store an object which you might not wish to load along with its containing object. The following are typical situations where storing is used:
when objects are stored in a database, such as a relational database, various indexes to the database are accessed, but not every object is loaded into RAM when the database is opened.
embedded objects in documents. An object represented by an iconic door is not loaded until that door is opened; an object represented by a glass door may not be loaded until the glass door is required to be displayed.
when there is additional information to allow various levels of access to complex data streams. For example, rich text. The text is stored in one stream, but the formatting information is stored in other streams; this enables global text or even plain text to be read without the details of the rich text formatting interfering with the process.
when there is additional information for later versions of a program. Additional version-2 information can be stored in a separate stream; then, a version-1 program working on the same store will load only the version-1 information, but the version-2 program will load both.
In general, the decision to store rather than externalise is a fundamental characteristic of the object, and should be taken with care. A compound object, which contains stored component objects, must obey store-related protocols which are more complex than the simple stream-related ExternalizeL() and InternalizeL(). The decisions already taken by system components, such as rich text, and by the application architecture, influence the kinds of things you store in your own applications.