Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Object serialization - how to?

3 views
Skip to first unread message

Szyk Cech

unread,
Jul 28, 2019, 5:33:11 AM7/28/19
to
Hi!

I want to write my education database app. But before I start it I want
to write decent database serialization and update system. This system
will allow me to follow good advice: DRY (don't repeat yourself). In
this case I don't want reimplement my objects definitions one in C++ and
two in SQL. In order to do this I will extend a bit C++ class
declarations with dumb defines: PRIMARY_KEY,
FOREIGN_KEY(class.variable1, class.variableN), INDEX, NO_STORE). This
defines have only matter for my class definitions parser. This parser is
input for SQL structure generator and for SQL upgrade patches. The only
not automated matter is migrateData() function (it is generated broken
in order to avoid destroy database by mistake).

This allow me to fully automatic database structure tracking with
automatic patches.

In true I did this already.

I have class hierarchy like this:
Database1<-Database2<-DatabaseN
Where every DatabaseX has update() and migrate() functions.

Then I have some thing like this:
using Db = DatabaseN;
class DbMyApp : public Db
{
// Specific app db/SQL calls here (covered by C++ functions)
};

This allow me to use lastly generated database in my app (without any
global renaming or something like this) - this allow minimize needed
changes in the code.

So I have one huge DatabaseN class aka Db and it serialize and
unserialize all storable classes in my app.

But in my new work I see some thing different than my approach. They
implement serialization abstract class and then for every storable class
they implement separate serialization class.

My question is that:
What approach is better? And why? One global serialization class or
maybe one serialization class for each storable class?

I thing that my implementation is better, because I have care only for
one, huge Database class, I have no problems with renaming many of them,
I don't have remember how my serialization classes are named, many
includes are not needed. So it is handy in one big generated class.

What is bad: test Database class generator and Sql patches generator is
kind of night mare in both approach. Because you have to write program
which test program which generate programs. But I proudly did it once.
But I want it make better next time (in Qt independent way, because in
the future I want to drop this lib entirely).

Thanks in advance and
best regards
Szyk Cech
0 new messages