The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Breaking the Last Dependency
Subject:  Nice idea, shame about the design.
Date:  2005-06-02 14:58:17
From:  infernoz


I've written better factories than this myself.

I would never ever reload a properties file on every instatation, very inefficient, use a Map instead and load early, to break early. I would not use a properties at all, instead I prefer using several ClassName.class objects in a Map, so that errors get caught at compile time. This method does not even require reflection for Beans e.g. just class.getInstance();

Another method I use is to have a list of objects with a test method (define by an interface or super class), which is called in sequence until you get a match, then call another method (also define by an interface or super class) to make an instance to return.

If no match is found by a factory it MUST always throw an exception (possibly an unchecked Exception) it is brain dead to just return null!

 Feed java.net RSS Feeds