I have this problem in Android/Eclipse.
I´m working in Android Project , this one has to be configured in different ways for different customers, this configurations are not similar(very different methods) between them.
The code is shared in 90%, but each customer has his own requirements.
Each customer has a package with diferent and multiple classes.
I would like only include package of choiced customer in the final compiled file.
But i have conditional object creation in my shared code, and i have to join all package for compiling.
More or less is this (Example)
//import every customer packages
import com.project.customer_1
import com.project.customer_2
import com.project.customer_3
…..
import com.project.customer_98
import com.project.customer_99
……..
final static int customer=2; //Define the customer for this compilation
………
if (customer==1) { //unreachable code
customerClass1 customer1=new customerClass1();
customer1.method1_1;
customer1.method1_2;
customer1.method1_3;
}
else if (customer==2) {
customerClass2 customer2=new customerClass2();
customer2.method2_1;
customer2.method2_2;
customer2.method2_3;
}
…….//unreachable code
else if (customer==98) {//unreachable code
customerClass98 customer98=new customerClass98();
customer98.method98_1;
customer98.method98_2;
customer98.method98_3;
}
else if (customer==99{//unreachable code
customerClass99 customer99=new customerClass99();
customer99.method99_1;
customer99.method99_2;
customer99.method99_3;
}
............
Is clear when customer=X, the other choices are unreachable code. I would like exclude other customer packages/classes than customer is choiced in compiled file. But exist dependency in code
Note: For me is not valid comment code, neither reflection.
You shouldn't do it in way you've described.
You should create additional level of abstraction to access data/logic specific to customers. And move that customer specific logic/data to separate libraries/projects.
To work with separated customer projects, your abstraction level should use dynamic class loading.
Edit. If you can't refactor your project, you can create Proguard config files for each customer to remove unreachable code.