2. You have two factory classes that both return a generic list of a data object class. Currently you are using a switch statement to call a particular factory depending on some input. Code below the switch depends on getting the list of data objects from different sources, but processing them the same.
List<Product> products = null;
switch (i)
{
case 1:
products = ProductFactory.GetProducts();
break;
case 2:
products = ItemFactory.GetItems();
break;
default:
break;
}
The problem is that if you wanted to add more factories from different sources you would have to rewrite the code for the current builder class, i.e. add more statements to the switch. Since an unknown number of factory calls could be made to get the data objects from different sources (one factory returns from Oracle, one from SQL one from SAP, etc) the code needs to accommodate any new factory sources without having to recode.
Describe how you might accomplish this, write code to show your solution. Be as verbose as needed.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|