dynamic behavior of factory class

Posted by manu1001 on Stack Overflow See other posts from Stack Overflow or by manu1001
Published on 2010-06-18T06:31:54Z Indexed on 2010/06/18 6:43 UTC
Read the original article Hit count: 310

I have a factory class that serves out a bunch of properties.

Now, the properties might come either from a database or from a properties file.

This is what I've come up with.

public class Factory {

    private static final INSTANCE = new Factory(source);

    private Factory(DbSource source) {
        // read from db, save properties
    }

    private Factory(FileSource source) {
        // read from file, save properties
    }

    // getInstance() and getProperties() here
}

What's a clean way of switching between these behaviors based on the environment. I want to avoid having to recompile the class each time.

© Stack Overflow or respective owner

Related posts about java

Related posts about design