Suppose I have an Animal interface and particular classes implementing it Cat and Dog. Right at the entry to the program, there's this:
if (choice == 0) {
Animal A = new Cat();
}
else if (choice == 1) {
Animal A = new Dog();
}
I'd like to have the choice parameter be populated at compile time (e.g., during Maven build), so that:
- if I compile with choice == 0, the Dog class doesn't get compiled
- if I compile with choice == 1, the Cat class doesn't get compiled
The reason for this is that 'Cat' and 'Dog' classes have separate/different dependencies.
Basically, the goal is to have one build for "A is a Cat" and another build for "A is a Dog". When I package the JAR, the use case for running the JAR will be either for 'Cat' or for 'Dog' (depending on the environment), never both 'Cat' and 'Dog' - so, there is no need for all dependencies to be in the project.
What is the best way to achieve this?