I am struggling with a design that meets all my requirements
I have a set of algorithms that can be performed individually, or combined in various configurations to produce additional outputs.
These algorithms can be costly, and if they are run once, the result should be cashed fo later use.
The Algorithms can be used in different contexts.
The algorithms should be open for extension so they are able to keep up with yearly standards revisions.
The design should be maintainable
My first attempt to satisfy these was to use the Strategy pattern with the following design…
The output from the behaviours calculations are cached in the behaviours themselves.
This satisfies requirements 1,2,3, but not 4.
The call to CalculateOutput() requires 30 different parameters, it’s own, and those necessary to allow it to call the other concrete behaviours. A change to the parameters for one function, will have a knock on effect, and often results in all behaviours having to update their parameter list.
Furthermore, the caching system did not work correctly as there was not always a 1:1 mapping between behaviours. For example, to produce an output from the EnergyBehaviour, it needs to perform multiple calls NHSolarPosition. How can “NHSolarPosition” cache multiple “angleOfIncidence_”s for only a single cached “outPut_”?
I tried to address the above issue, by encapsulating all parameters in their own type “PVPanel”, and passing this to behaviours. This was problematic for two reasons. Firstly, there was a significant overhead in calls to simple behaviours, as only a couple of parameters might be required, however there were many other parameters that were not being used, or relevant. Secondly, passing a “PVPanel” type into the behaviours caused requirement 2 to fail, I was not able to use the behaviours in a context other than in relation to PVPanels.
I am struggling to reconcile all my requirements into a single, elegant design.
