darkadept
15th March 2007, 22:50
I'm designing a database app where I want clearly defined lines between my UI, Business Objects, and Data Access Layer. I've found a ton of Java material on the subject but almost no C++ material. And pretty near zero amount of Qt material on this. I'm creating a test program to flesh this idea out. The test program is a simple contact database with a single business object, the Contact object. I know DAO/ORM is overkill for this test program, but I'm doing this research for a much larger application.
I first stumbled upon the DAO (Data Access Objects) design pattern and that seems to fit the bill. I have a rough implementation of DAO already (complete with factories) but the problem exists where I have to change my DAO factory interfaces and add a new DAO object for each Business object I create. This seems like a lot of extra work (which is ok if it's the only way to go.... but I'm always on the lookout for a "Better Way[TM]")
I have discovered this website (http://www.javaworld.com/javaworld/jw-03-2002/jw-0301-dao.html) that explains how to make a generic DAO object (based on CRUD) so that when you implement a new database type (let's say CSV text files instead of sql) you only have to implement this generic DAO object. With Qt4 I would use the plugin architecture to provide generic libMysql.so, libCSV.so, ... plugins. This would be a beautiful solution in my eyes but that website is for Java and I have trouble making the leap to C++.
This approach sounds very much like the ORM (object relational mapping) model to me. So I started to research ORM. Of course a ton of Java information abounds focusing a lot on Java's Hibernate libraries.
Thinking ORM might be too much for me I tried messing around with C++ templating and generics. I managed to make a few changes to simplify the DAO layer but not a whole lot.
So my questions are which way should I go? Is there a decent/easy-to-use ORM library for C++ (or more specifically Qt4)? Is there a better way to do DAO? Is there another method altogether?
Remember I'm trying to stick to C++ and Qt4 and OpenSource if at all possible. It also has to be a cross-platform solution. Why is it the Java people have all the fun in this topic? :p
I first stumbled upon the DAO (Data Access Objects) design pattern and that seems to fit the bill. I have a rough implementation of DAO already (complete with factories) but the problem exists where I have to change my DAO factory interfaces and add a new DAO object for each Business object I create. This seems like a lot of extra work (which is ok if it's the only way to go.... but I'm always on the lookout for a "Better Way[TM]")
I have discovered this website (http://www.javaworld.com/javaworld/jw-03-2002/jw-0301-dao.html) that explains how to make a generic DAO object (based on CRUD) so that when you implement a new database type (let's say CSV text files instead of sql) you only have to implement this generic DAO object. With Qt4 I would use the plugin architecture to provide generic libMysql.so, libCSV.so, ... plugins. This would be a beautiful solution in my eyes but that website is for Java and I have trouble making the leap to C++.
This approach sounds very much like the ORM (object relational mapping) model to me. So I started to research ORM. Of course a ton of Java information abounds focusing a lot on Java's Hibernate libraries.
Thinking ORM might be too much for me I tried messing around with C++ templating and generics. I managed to make a few changes to simplify the DAO layer but not a whole lot.
So my questions are which way should I go? Is there a decent/easy-to-use ORM library for C++ (or more specifically Qt4)? Is there a better way to do DAO? Is there another method altogether?
Remember I'm trying to stick to C++ and Qt4 and OpenSource if at all possible. It also has to be a cross-platform solution. Why is it the Java people have all the fun in this topic? :p