473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Design question: interrelated classes

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
0 1194

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Danimal | last post by:
I have been using PHP for a long time... since it was called PHP/FI. I have a programming design question: Let say I have this class: class attrib { var $lenght; var $type; ... }
9
by: Patchwork | last post by:
Hi Everyone, I have a design related question (in C++) that I am hoping someone can help me with. It is related to my previous post but since it was pointed out that I was more or less asking...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
13
by: KV | last post by:
I'm new to OO Design, and I'm fixing to start writing my very first C# program. Given the complexity of OO programming, I would like to run something by this group and get general input. My...
1
by: Andy Fish | last post by:
Hi, I am about to commence the design of what will turn out to be a fairly large asp.net web app, and I am looking for any good advice and resources (books, web pages) concerning how best to...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
10
by: Frank van Wensveen | last post by:
Friend, coders, fellow wage slaves, lend my your ears. I believe that in a perfect world the design of a website (or feature on a website) should be totally separated from its design and the data...
12
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.