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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:17:28+00:00 2026-05-27T16:17:28+00:00

I have a set of DAOs ( Data access objects ) that need to

  • 0

I have a set of DAOs (Data access objects) that need to be fetched from a DAOFactory (using the factory-method pattern).

Now we have the case that DAOs must always be initialized with parameters e.g.: (with String params)

MyDataDAO myDAO = new myDAO("myProject", "myProjectWallName");

Now, having a bunch of DAOs has required us to refactor (using the factory pattern) and here are the conflicting forces:

  1. If we refactor our DAOs to NOT use any default arguments (probably a good thing) we may land up having setters/getters for the mandatory members that MUST be initialized. Implying probably null checks/assertions littered all throughout (bad thing IMO)
  2. The other way is to force every method of the DAO to carry the corresponding mandatory arguments along with what they already have (too much data/long parameter list – probably bad but maybe the only choice?)
  3. Use Spring! Well we do for some of the purely stateless DAOs which really don’t require any defaults to be set up. But I don’t think Spring really supports run-time constructor-parameter initialization, since it creates and caches the objects at start-up. So back to square one (Spring may support this but I really haven’t been able to find anything about this as yet. Help? 🙂

So how should one go about designing a ‘good’ interface for the classes that are to be instantiated using a factory i.e., best practices to follow in this regard. I’ve always encountered the non-parameterized constructor case up until now where I do feel a valid need/reason for having the parameters. I personally feel it’s bad OO to have a default constructor only and set everything through setters-getters, defeating the very purpose constructors exist to solve!

Confused…

  • 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-27T16:17:29+00:00Added an answer on May 27, 2026 at 4:17 pm

    A Factory pattern is used to create an object and make sure that it is in a valid state when it’s returned to the caller.

    If your object has required properties, returning it with a default constructor and not initialized properties, won’t return a valid state to the caller. In such a case, everywhere you call the factory, the code should also know which fields are required and initialize them after the factory call. That way you duplicate initialize code (and knowledge) and the whole idea of the factory pattern is to remove such duplication.

    So required fields should be passed as parameters to a factory method.

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

Sidebar

Related Questions

I understand separating the data layer objects (DAOs) in their own layer that abstracts
I have a (DAL) Data Access Layer (but this question is relevant for DAOs
I have set up a version control system using TortoiseSVN at my home to
I have set up a Django application that uses images. I think I have
I have set up a url mapping that goes like this: (r'enroll/$', 'enroll') In
I have set the size of the tableView that I show as the popoverController
I have this idea that using SQL VIEWS to abstract simple database computations (such
I have set up an asset host at assets.domain.com but it appears that cookies
I have set up cruisecontrol.net cs for my project that has a number of
In my application I have a set of of DAOs which I inject into

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.