Answer the question
In order to leave comments, you need to log in
How to develop a competent application architecture: working with a database?
How to properly design a layer responsible for working with a database in an application?
Why is the approach when all read / write operations are performed by a separate DbManager class bad?
How to do it right? Relevant classes UserService, ArticleService, etc., which will be responsible for this? But then you still need a class that will be tied to a specific implementation (for example, working with the MySQL database through the JDBC driver), right?
What are the pros and cons of both solutions? Maybe it needs to be done in a different way?
Previously, the approach from the first diagram seemed correct and logical to me, but recently I come across mentions that this should not be done (literally today, for example, here ).
Answer the question
In order to leave comments, you need to log in
The first approach is bad in that you create a God-object in it, it takes on too much responsibility, which is contrary to the SRP principle . The class will have a large size and will constantly change as functionality changes.
The second approach is almost correct. The only missing interfaces are UserServiceInterface and ArticleServiceInterface, which describe data access methods. Usually such interfaces are called Repository, not Service. These interfaces must be implemented in concrete classes such as OracleUserService and OracleArticleService. To interact with the database, these classes use only session (Session) or connection (Connection). In your example it is DbHandler.
Read about the Hibernate appliance. He uses the second approach.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question