3

I have a SQL database to which I store and from which I read several objects into my C++ code.

I wrote a single database wrapper which handles all the reads and writes to the DB.

Of course this class got too large. I could make a Database wrapper for each business object but then I have to instantiate all these different wrapper classes.

Since this seams like a pretty generic situation, I am wondering what's the text book way of wrapping a database?

1
  • This is known as a Object Relational Mapping (ORM).
    – Ben
    Jun 20, 2016 at 14:51

1 Answer 1

1

You have to have the same amount of code, regardless whether it all lives in a single large class or several smaller classes!

An ORM can help you write this code, but if we're talking about organisation of higher level DB repository for your business objects, you don't have much choice. Its easy to create many classes to handle DB transactions between business objects though, group related schema elements together and create a class for each (eg one for Customers, one for Stock or whatever your system works with).

Once thing that is useful is to ability to split your business objects into horizontal slices and maintain them completely separately (ie a microservice architecture), so bearing this in mind might make the decision of which DB areas to split into smaller classes easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.