I have a piece of code where I started applying a strategy template, let's say this:
IStrategy
StrategyA : IStrategy
StrategyB : IStrategy
StrategyC : IStrategy
The interface has only the Calculate method. After implementation, it turned out that all 3 specific types have the same code for the Calculate method and two identically named properties, only with different values.
So, to remove duplication, I made the interface an abstract class and moved the method and properties before, just setting the base properties with their corresponding values from the inside of the construction of specific types.
Now I know that templates are not hard and fast rules, but only recommendations, but I have distorted it so far from recommendations that I cannot help but think that there is another template that I should look at?
Can anyone suggest any other approaches, please leave me so that it is easy to add new “Strategies” along the line. It may turn out that we need to change the logic in some of these new cases, since I could structure it so that I don't have code repetition, but I have a flexible design that allows me to change things in a line?
Thank.
source
share