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 7047043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:43:23+00:00 2026-05-28T02:43:23+00:00

Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();

  • 0

Consider following simple DAO example:

public abstract class DAOFactory
{
    public abstract AccountDAO getAccountDAO();
    public abstract MessageDAO getMessageDAO();

    public static DAOFactory getDAOFactory(int whichFactory)
    {
        // depending on whichFactory
        return new SpecificDAOFactory();
    }
}

public interface AccountDAO
{
    public void add(Account account);
    public void delete(Account account);

    public int authenticate(Account account); // another source!
}

public interface MessageDAO
{
    //other methods
}

All above mentioned methods have to be implemented using the same data source, except AccountDAO.authenticate().

Authentication information available at the other data source and should be pluggable in turn (e.g. could be SQL, LDAP, etc.). At the same time, authentication data source is independent from the DAO data source, i.e. whichFactory could be A, B or C while authentication source X or Y.

From interface design point of view, authenticate fits nicely into AccountDAO. But from implementation point of view I feel uncomfortable.

What would be better design which will provide clear data access layer interface and implementation?

  • 1 1 Answer
  • 2 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-28T02:43:23+00:00Added an answer on May 28, 2026 at 2:43 am

    Data access objects tend to follow the same structure and pattern, so you might want to consider creating a higher level class encapsulating this shared logic. I will highlight with an example, please note that I am omitting interfaces because I rarely find them useful at the DAO level.

    Base DAO class:

    public class BaseDAO<T> {
        private Class<T> clazz;
    
        public BaseDAO(Class<T> clazz) {
            super();
            this.clazz = clazz;
        }
    
        public T find(Long id) { ... }
    
        public List<T> findAll() { ... }
    
        public T create(T entity) { ... }
    
        public T update(T entity) { ... }
    
        public void delete(T entity) { ... }
    }
    

    A derived DAO for a hypothetical Account object

    public class AccountDAO extends BaseDAO<Account> {
        public AccountDAO() {
            super(Account.class);
        }
    
        public List<Account> findByAccountStatus(String status) { ... }
    }
    

    As you can see, you greatly minimize the amount of code in derived DAO’s. With this setup you do not need to use a factory, just initialize your DAO’s directly.

    As far as your second question, I would not place an authenticate method on the Account DAO. Authentication should be dealt with at a higher level of abstraction (fits very nicely in the service layer), even if it eventually retrieves some information from the data access layer.

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

Sidebar

Related Questions

Consider the following simple example: [DataContract({0}Base)] public class Base<T> where T : Entity<T> {
Please consider the following simple use case: public class Foo { public virtual int
Consider the following simple map: class MyCoolMap : public unordered_map<const char *, const char
Consider the following simple RESTEasy (JAX-RS) service: @Path(/example-service) public interface ExampleService { @Path(/ping) @GET
Consider the following simple example class, which has a property that exposes a modified
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
Consider the following simple polymorphism ... class Parent { public: someFunc() { /* implementation
Consider following simple example: Area.hh #pragma once class Area; #include <QScrollArea> class Area :
Consider a following chunk of service: public class ProductService : IProductService { private IProductRepository
Consider the following entity class, used with, for example, EclipseLink 2.0.2 - where the

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.