What technology for storing data of desktop, object-oriented application?
Say I'm codi开发者_运维知识库ng a standalone desktop application. Say it's object-oriented and it needs to save its data into a file. The data is normally stored in different classes. Inheritance is involved.
SQLite seems to be a common choice but its support for inheritance is somewhat poor and implementing it requires resorting to different tricks so I wander if there are better, more flexible options?
(assume that creating my own data format is not an option)
EDIT: More specifically, I'm currently working with Windows and C#, though for the future I would also be interested in C++ solutions.
There might not be a reason to use a relational database to store the data. OO-RDB relational mapping tools are abundant, but add a more complexity and failure points to an application. C#/.Net provides nice a Serialization interface (http://goo.gl/zmyeo). Using .Net's serialization, objects can be written to a file in either XML or binary format. The XML or binary file can then be "de-serialized" back into objects. It's generally fast and convenient, and usually sufficient for a prototype.
Some advantages of relational databases are they support SQL (making it easy for other applications to use the data) and they support many users accessing the same data set. Once the application is working or it outgrows the functionality offered by Serialization, look into moving it to a relational database like SQLite.
The C++ issue is a little harder. C++ does not offer any out-of-the box serialization. Its lack of reflection makes it tough to write and maintain object persistence code. My own strategy is to avoid C++ for OO application, if possible. If C++ is a must, take a look at some of the OO-RBD mapping tools for C++: http://goo.gl/7ytOV.
PS: As the application evolves class and attribute names are changed, added, and deleted. Reading back in serialized objecs from an older code base presents problems-- the contents of the file do not match the structure of the (updated) classes. C# provides a facility that lets you migrate old objects to new objects. If you go the Serialization route, check into that.
精彩评论