Sooner or later, in almost every serious project a fundamental question comes up: "How will users load and save data?" Depending on the complexity of the project, that question can have a wide range of answers. For example, a simple address book application might only need to handle a single address book entry class; saving to a file might simply involve calling a method of the class called Write and passing it an std:: ostream&. Loading from a file could be equally simple—just read in an integer indicating the number of records in the file, and call a Read method that many times. On the other hand, consider a full-scale computer-aided-design application. Its database is likely to be incredibly complicated, perhaps containing graph-like structures representing topology, reference-counted shared pointers, template classes, multiple inherited classes, abstract base classes, and the like. In such cases, simple Read/Write methods are cumbersome to implement and can lead to all kinds of maintenance nightmares as developers forget to update them, or update them incorrectly. When data needs to be upgradeable from one release of the application to the next, the nightmares get even worse.
展开▼