I have the following class:
public class MotherFactory {
private String food = "banana";
private static FoodFactory<Banana> foodFactory = new BananaFactory();
public MotherFactory() {
}
}
In this class i declare a FoodFactory for BananaHsm, which i hardcoded in (The food string has no use in this yet). What i want however, is that the declaration of the FoodFactory changes according to the food String. E.g.: For private String food = "apple"
, <BananaFactory>
changes to <AppleFactory>
, and new BananaFactory()
to new AppleFactory
and so on. i already thought of using a switch or if/else, however these would be declared inside the constructor, which doesnt make the variables usable for the whole instance.
Are there any ways to do this?