Putting it All Together
You've seen most of the fundamental operations required to store data in an OPC package. To demonstrate how all this code hooks together, the
sample code for this article combines all the code you've seen so far with a simple user interface (see
Figure 4) that lets you create or open an album, and add and remove pictures.
 | |
| Figure 4. Explore OPC: This sample application illustrates the principles of storing, associating, and retrieving information from OPC. |
OPC Recommendations
Although you've seen how to perform the individual operations required to work with OPC, when you're building a real-world application, you'll want to follow these recommendations:
- Chunk data: You probably noticed that the article example associated a separate XML file with each image rather than creating one big XML file for the entire album. One advantage of this approach is that you won't lose all your data if the package somehow gets corrupted.
- Use indirection: Rather than referencing stored data directly, you can use relationships to reference the same data from multiple parts. For example, if you use the same image 50 times in a Word document, you only need to store one copy of the image. This both reduces the amount of space necessary to store the document and allows you to replace that image in all 50 locations in your document with one operation.
You've seen that OPC can be used to store disparate data types in a single container. This approach has many advantages over using a directory of files including organization and portability. While OPC isn't a replacement for a full-blown database, it is a compelling choice to store many kinds of application data.