I have tried to ask a variant of this question before. I got some helpful answers, but still nothing that felt quite right to me. It seems to me this shouldn\'t really be that h
I would tend to start with an enumeration ProjectSize {Small, Medium, Large}
and a simple function to return the appropriate enum given a numberOfManuals. From there, I would write different ServiceHourCalculators
, the WritingServiceHourCalculator
and the AnalysisServiceHourCalculator
(because their logic is sufficiently different). Each would take a numberOfManuals, a ProjectSize, and return the number of hours. I'd probably create a map from string to ServiceHourCalculator, so I could say:
ProjectSize projectSize = getProjectSize(_numberOfManuals);
int hours = serviceMap.getService(_serviceType).getHours(projectSize, _numberOfManuals);
This way, when I added a new project size, the compiler would balk at some unhandled cases for each service. It's not all handled in one place, but it is all handled before it will compile again, and that's all I need.
Update I know Java, not C# (very well), so this may not be 100% right, but creating the map would be something like this:
Map serviceMap = new HashMap();
serviceMap.put("writing", new WritingServiceHourCalculator());
serviceMap.put("analysis", new AnalysisServiceHourCalculator());