views:

637

answers:

3

Hi all,

I would like to implement a data access object pattern in C++, but preferably without using multiple inheritance and/or boost (which my client does not like).

Do you have any suggestions?

+2  A: 

OTL (otl.sourceforge.net) is an excellent C++ database library. It's a single include file so doesn't have all the complexity associated (rightly or wrongly!) with Boost.

In terms of the DAO itself, you have many options. The simplest that hides the database implementation is just to use C++ style interfaces and implement the data access layer in a particular implementation.

class MyDAO {
  // Pure virtual functions to access the data itself
}

class MyDAOImpl : public MyDAO {
  // Implementations to get the data from the database
}
JeffFoster
I can see how that provides an abstract interface to data access operations, but I wonder how the domain objects relate to the MyDAO object to get instantiated and persisted.
andreas buykx
The answer is the Object-Relational Impedance Mismatch. Pour yourself a stiff drink and Google it.
moffdub
+1  A: 

A quick google search on data access object design patterns will return at least 10 results on the first page that will be useful. The most common of these is the abstract interface design as already shown by Jeff Foster. The only thing you may wish to add to this is a data access object factory to create your objects.

Most of the examples I could find with decent code are in Java, it's a common design pattern in Java, but they're still very relevant to C++ and you could use them quite easily.

This is a good link, it describes the abstract factory very well.

Odd
+1  A: 

My preferred data access abstraction is the Repository Pattern.

moffdub