Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 539469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:08:20+00:00 2026-05-13T10:08:20+00:00

I’ve noticed that having a data access object (DAO) interface and implementation is really

  • 0

I’ve noticed that having a data access object (DAO) interface and implementation is really starting 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 this same interface an implementation for each of my entity classes. Before I get crazy with a refactoring, I’m wondering if there are any suggest patterns to apply here? I had a few ideas of my own:

  1. Use the template pattern to factor out all of the boilerplate code and delegat to specific DAO’s when needed. This may reduce code, but I think the number of interface and class files would be the same.

  2. Describe the interface and implementation using generics, then parameterize the implementation with the specific DAO I need. Again, this would reduce code but I think the number of files would remain the same. Also, I”m not sure how this would work as my generics skills aren’t strong yet. This is my preferred choice so far though. Is anybody else using a similar strategy?

  3. Create an abstract base DAO class that implements common functionality, then extend it with the more specific DAO classes for the details. This would save me the trouble of creating so many interfaces, although the names of DAO methods could not be specific to an entity (e.g i couldn’t use findDogById(), it would have to just be findById() ).

  4. Finally because different access schemes may be involved when retrieving data (Hibernate, JPA, iBatis etc), it would seem like swapping implementations is desirable. This fits well with the strategy pattern.

What is the most elegant and efficient approach to developing DAO’s? Which approach best favors reuse and minimizes redundancy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:08:21+00:00Added an answer on May 13, 2026 at 10:08 am

    You could look at generic dao.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 388k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, ImageMagick. It has a Java API - JMagick. If… May 15, 2026 at 12:22 am
  • Editorial Team
    Editorial Team added an answer I figured it out! If you want to preload the… May 15, 2026 at 12:22 am
  • Editorial Team
    Editorial Team added an answer There are other flash based solutions other than SWFupload. Have… May 15, 2026 at 12:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.