Note that there are some explanatory texts on larger screens.

plurals
  1. POIf the factory pattern forces you to use default constructors then how should one design the class interface requiring parameterized constructors?
    primarykey
    data
    text
    <p>I have a set of DAOs (<a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html" rel="nofollow">Data access objects</a>) that need to be fetched from a DAOFactory (using the factory-method pattern).</p> <p>Now we have the case that DAOs must always be initialized with parameters e.g.: (with String params)</p> <p><code>MyDataDAO myDAO = new myDAO("myProject", "myProjectWallName");</code></p> <p>Now, having a bunch of DAOs has required us to refactor (using the factory pattern) and here are the conflicting <em>forces</em>:</p> <ol> <li>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)</li> <li>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?)</li> <li>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? :)</li> </ol> <p>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 <em>bad</em> OO to have a default constructor only and set everything through setters-getters, defeating the very purpose constructors exist to solve! </p> <p>Confused...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload