I want to loop through all of the classes (Outlook, Temp, Humidity) and, for each of them, calculate information gain. This is a function that makes use of each possible value of a given attribute (Outlook, Temp, Humidity).
One possibility would be to define a common interface implemented by all the attributes. This would allow your information-gain function to use the same interface regardless of attribute. And no reflection is required. For example:
interface IAttribute {
Enum<?>[] getValues();
String getName();
}
This interface applies to attribute classes as a whole, and not a particular attribute value. Here's one way to do that.
private static final class OutlookAttribute implements IAttribute {
enum Outlook { SUNNY, RAINY, CLOUDY }
@Override
public Outlook[] getValues() { return Outlook.values(); }
@Override
public String getName() { return "Outlook"; }
}
// And similarly for Temperature and Humidity
Now you can create a list of attributes to pass to your function.
List<IAttribute> attributes = new ArrayList<>();
attributes.add( new OutlookAttribute() );
attributes.add( new TemperatureAttribute() );
attributes.add( new HumidityAttribute() );
And your function definition can iterate through attributes.
for ( IAttribute attribute : attributes ) {
Object[] values = attribute.getValues();
...
for ( Object value : values ) {
...
}
...
}