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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:33:28+00:00 2026-05-30T09:33:28+00:00

I currently have some DAOs set up using the abstract factory pattern. It looks

  • 0

I currently have some DAOs set up using the abstract factory pattern. It looks something like this:

public abstract class DaoFactory
    public static GetDaoFactory()
    public abstract IPersonDao GetPersonDao()
    // etc.

the static GetDaoFactory() returns an underlying SqlDaoFactory. Until today, all Daos have worked with the same SQL database. Now, I would like to add another DAO to this factory, however the DAO will interact with an external service instead of the SQL database (Let’s say this is GetCompanyDao()). I would essentially like just to add this GetCompanyDao() method to the abstract DaoFactory class so the public interface is completely decoupled from the underlying implementation (no need/way to tell if the particular dao is using SQL or the external service).

Should I simply rename the SqlDaoFactory to something more appropriate and include the GetCompanyDao() method there, so that this DAO Facotry now uses SQL for some DAOs and an external service for the other? Or is there a different way to accomplish this?

  • 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-30T09:33:29+00:00Added an answer on May 30, 2026 at 9:33 am

    Renaming it is totally upto you. DAO pattern abstracts any type of data access not necessarily a Database access. So you can definitely go ahead with your plan.

    You can use a framework like spring, instead of manually creating the patterns.

    I had tried hardcoding these patterns just once.

    public abstract class DAOFactory {
    
      // List of DAO types supported by the factory
      public static final int MYSQL = 1;
      public static final int ORACLE = 2;
      public abstract UserDAO getUserDAO() throws SQLException;
      public static DAOFactory getDAOFactory(int whichFactory) {
    
        switch (whichFactory) {
          case MYSQL: 
              return new MySQLDAOFactory();
          case ORACLE    :
              ......
    
    
    public class MySQLDAOFactory extends DAOFactory {
    
        public MySQLDAOFactory() {
        }
        public static final String DRIVER= "/*driver here*/";
        public static final String DBURL="/*conn string here*/";
        /* instead of using constants you could read them from an external xml file*/
    
        public static Connection createConnection() {
            /*create connection object here*/
            return conn;
        }
        public UserDAO getUserDAO() throws SQLException{
            return new MySQLUserDAO();
        }
    
    public interface UserDAO {
        public int insertUser(String fname, String lname);
        public ArrayList<User> selectUsers();
    }
    
    public class MySQLUserDAO implements UserDAO {
    
        Connection conn=null;
        Statement s=null;
        public MySQLUserDAO() throws SQLException{
            conn = MySQLDAOFactory.createConnection();
            s = conn.createStatement();
        }
    
        public int insertUser(String fname, String lname) 
        {
            //implementation
        }
    
    
        public ArrayList<User> selectUsers() 
        {
            //implementation
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have some code that looks like: -(UIView)someMethod { CGRectMake(0,0,100,100); UILabel *label =
I'm using Zend_Search_Lucene, the PHP port of Java Lucene. I currently have some code
Currently i have some interfaces (stripped down for here): public interface IJobGroup { string
I currently have some python code I'd like to port to C++ as it's
I currently have some expectations set up on a mock with consecutive calls: The
I have some strings, entered by users, that may look like this: ++7 7++
Currently I have some code that is doing an SFTP via expect/tcl. Its something
I currently have some code which grabs some JSON from a site. This is
I currently have some large strings that I would like use as test data

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.