By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,420 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,420 IT Pros & Developers. It's quick & easy.

Design question: interrelated classes

P: n/a
I'm developing a library to allow interaction with an SQL database.
Rows in the database are represented with by a user-defined row class
with the following inheritance hierarchy:

SigC::Object libsigc++ object (allows calling of class
^ methods by slots in response to signals)
|
libpqxxobject::row_base common row state (whether modified, and
^ if initialised etc.) + signal emission
|
libpqxxobject::row<RowType> common templated methods:
^ insert/update/delete/refresh
|
RowType row-specific class, holds the column data
and methods to interact with it

The class may be created "blank" as a new record or as a result of a
database query. It may then be inserted into the database, updated or
deleted from the database using this class:

libpqxxobject::connection_proxy interface to database. Handles connection,
^ transactions, recursive object serialisation
|
libpqxxobject::row_convert<RowType> pure virtual functions to erase, insert,
^ update and refresh rows
|
RowTypeConversion implementations of the above functions
friend class of RowType

The user can interact with the row object, and when interaction with
the database is required, they use the row conversion class, like
this:

RowType myrow(foo, bar);
....
RowTypeConversion rc(connection);
rc.insert(myrow);
That worked fine, but there's a rub: when you update an object, it
needs to then be refreshed from the database, whether it committed or
aborted. This can't be done manually, since for complex classes,
objects are recursively serialised, and may be modified or made
inconsistent during the process. This is provided for by a refresh()
method in the row_base class, but the row_base class doesn't itself
know how to refresh or use the database. The row_convert class
registers a signal to be delivered to each affected row on transaction
completion. The refresh() method takes a connection object, and I
then want to have the row refresh() method create a row_convert object
to refresh /itself/. Is this possible? Both classes need to call
each others methods, but I can't declare them both at once.

What is the best way to achieve what I want? I can't combine them as
one class, since I want to keep the serialisation logic separate from
the row class. However, I do need to allow an object to "request"
serialisation somehow in response to it receiving a signal.
Another problem is that SigC::Object only provides a private copy
constructor, so I can't copy the row class e.g. to put into a
container. I'm happy to use some form of reference-counting smart
pointer (any recommendations? I've only used Glibmm's Glib::RefPtr<>,
but I'd like something more standard). However, I will sometimes want
to make a copy, so I can make private modifications (i.e. a
working/scratch copy). What is the best way to do this?
Sort of related: I've only recently become aware of the concept of
"Design Patterns". I've only read very brief descriptions of a few
common patterns, and I'd like to learn more. Could anyone recommend
an good up-to-date book that covers all of the common patterns?
Many thanks,
Roger

--
Roger Leigh

Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.