DAO Naming Conventions

I am developing an application that should establish a connection to the database. To work through this connection, I use the DAO pattern. My question is related to the organization of the code and the name of the interfaces and implementations. The current package structure is as follows:

  • mainpackage
  • mainpackage.model β†’ Models of each table for creating objects with data from DB
  • mainpackage.persistence β†’ ConnectionManager
  • mainpackage.persistence.dao β†’ Interfaces and Implementations

I thought about naming interfaces that it would be nice to use something like ClassDAO and DefaultClassDAO for implementation, since I don’t know what to name it. What do you think? Is there any agreement for this?

+4
source share
1 answer

I would use the agreement described in the "Domain Managed Project" section.

  • mainpackage
  • mainpackage.model β†’ contains "repositories" as interfaces, such as UserRepository, ProfileRepository, which describe operations for managing your objects in the store (store, find, etc.). This way you don't leak that your repository is a DB.
  • mainpackage.model.db (or sql or something else) -> contains SqlUserRepository, SqlProfileRepository implements the interfaces in mainpackage.model and hits DB.

You can even put DB classes in another subproject. I consider it important not to put the database at the center of your design and just consider it as a implementation detail.

+2
source

All Articles