Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data access object pattern implementation

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?

like image 605
andreas buykx Avatar asked Jan 25 '23 02:01

andreas buykx


2 Answers

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
}
like image 185
JeffFoster Avatar answered Jan 26 '23 15:01

JeffFoster


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.

like image 40
Odd Avatar answered Jan 26 '23 16:01

Odd