Java: what is "best practices" way of controlling what class constructors to call at execution?
<p>I am trying to modify the block below and need to figure out "the right way" to do it:</p>

<pre><code>PRQ prq = new PRQ();
XYZ1 xyz1 = new XYZ1();
XYZ2 xyz2 = new XYZ2();

features = new ArrayList&lt;MyFeature&gt;();

// START OF MAIN BLOCK
// This is rigid: need to comment out lines and rebuild to exclude features
// Want to control this at execution time by a config file
//
features.add(new ABCFeatures());
features.add(new PRQFeatures(prq));
features.add(new XYZFeatures(xyz1,xyz2));
// ...
// END OF MAIN BLOCK

public class ABCFeatures extends MyFeature {
    public ABCFeatures()
    {
    }
}

public class PRQFeatures extends MyFeature {
    public PRQFeatures(final PRQ prq)
    {
    }
}

public class XYZFeatures extends MyFeature {
    public XYZFeatures(final XYZ1 xyz1,final XYZ2 xyz2)
    {
    }
}
</code></pre>

<p>So for every token of input data I compute a bunch of heterogeneous features. Some of those require resources to get computed and those are provided at instantiation (<code>prq</code>, <code>xyz1</code>, <code>xyz2</code>).</p>

<p>Right now if I want to experiment by running my code with some of the features turned off, I need to comment out the corresponding <code>features.add(new ...</code> line, rebuild the jar and then rerun. Too rigid! I want to control this at execution using some type of configuration file which says which of the features are on and which are off. </p>

<p>So 2 questions:</p>

<ol>
<li>Looks like I need to use <code>getClass().getDeclaredConstructors()</code>, but I am a bit confused about exactly how it's supposed to be used</li>
<li>Related to #1 I suppose: Is there a preferred way to specify the configuration? That is, should it be a JSON/XML file in some specific format? Is there existing machinery in Java to support exactly this type of scenario?</li>
</ol>