Creating a Database Access Object
Although we can use a dozen different methods to standardize our database functionality, a Database Access Object (or DAO) can be used efficiently to achieve this. This recipe is a working example of how to make your own, and begin organizing your functionality.
Getting ready
Database Access Object (from now on DAO) is used to simplify functionality to and from our database(s). The idea behind a DAO is to create mapping classes that have a single responsibility on their functionality. This means that, for example, we have a table called cards
, which also has a mapping called Cards
. This Cards
mapping will then contain all the functionality we need to use in that table.
This could include, for example, the CRUD (Create, Read, Update, and Delete) functionality, but also more complex methods such as calculations. The idea behind a mapping class is that we are able to hide the layout of the database and provide an interface for the rest of the application, which...