My DAO is starting to look the same, offering a patch design template?

I noticed that with the interface and implementation of the data access object (DAO) it really starts to add up:

public interface ForceDAO{
    public void store(Force force);
    public void delete(Long forceId);
    public Force findById(Long forceId);
    public List<Force> findAll();
    public void deleteAll();
}

I have the same interface - an implementation for each of my entity classes. Before I go crazy with refactoring, I wonder if there are any sentence templates that can be applied here? I had a few ideas of my own:

  • Use the template template to split all the template and delegate code into a specific DAO when necessary. This may reduce the code, but I think the number of interfaces and class files will be the same.

  • Describe the interface and implementation using generics, and then parameterize the implementation with the specific DAO I need. Again, this will reduce the code, but I think the number of files will remain the same. Also, I'm not sure how this will work, as my generic skills are not very strong yet. This is my preferred choice so far. Does anyone else use a similar strategy?

  • Create an abstract base DAO class that implements common functions, and then extend it with more specific DAO classes for details. This would save me the need to create so many interfaces, although DAO method names could not be specific to the object (for example, I could not use findDogById (), it would just have to findById ()).

  • , - , (Hibernate, JPA, iBatis ..), , . .

DAO? ?

+3
2
+4

, , . , 50+ .

Hibernate, JPA .. , , .., DAO.

.

+2

Source: https://habr.com/ru/post/1728260/


All Articles