samedi 18 juillet 2020

Run time instance creation of sub classes in template design pattern

I am creating an application which has three algorithms with some common piece of code . Hence i decided to go with Template Design Pattern. I need to decide the algorithm to be called at runtime like below

switch(filetype){
case "test":
BaseClass b = new SubClass1();
b.convert();

case "test2":
BaseClass b = new SubClass12();
b.convert();
}

i want to avoid the switch case while instance creation during run time and want to use Dependency injection to achieve the same. Could you suggest any pattern to achieve this.

Aucun commentaire:

Enregistrer un commentaire