I am trying to create a web tool for my company, which, in fact, uses a geographical input to obtain tabular results. Currently, three different business areas use my tool and get three different types of products. Fortunately, all outputs are based on the same idea of the Master Table - Child Table, and they even share a common table.
Unfortunately, in each case, the related rows in the Child table contain significantly different data. Since this is the only point of competition, I extracted the method FetchChildDatainto a separate class called DetailFinder. As a result, my code is as follows:
DetailFinder DetailHandler;
if (ReportType == "Planning")
DetailHandler = new PlanningFinder();
else if (ReportType == "Operations")
DetailHandler = new OperationsFinder();
else if (ReportType == "Maintenance")
DetailHandler = new MaintenanceFinder();
DataTable ChildTable = DetailHandler.FetchChildData(Master);
Where PlanningFinder, OperationsFinder, and MaintenanceFinder are all subclasses of DetailFinder.
I was simply asked to add support for another area of the business and would not like to continue this block trend if. I would prefer to have a parse method that looks like this:
DetailFinder DetailHandler = DetailFinder.Parse(ReportType);
However, I find it difficult to DetailFinderknow which subclass processes each line, or even which subclasses exist, without changing only the if block to a method Parse. Is there a way for subclasses to register with abstract DetailFinder?
source
share