
I have designed the sorting mechanism for my site as :
Now due to change in requirement, I need to add some variables which are common to all Strategy i.e ByDate, ByConsuption, By Demand.
Also I need to modify the sorting string, based on output of a function
for example if a function returns available then,
- SORT BY DATE DESC => sort by available desc, DATE desc
- SORT BY DEMAND DESC => sort by available desc, DEMAND desc
Question:
If I have some common variables/functions how can I include at one point and still it can be accessible in all classes?
I’d use a SortStrategyBase or SortStrategyAbstract class which will would have the common functionality, and then have the factory inject whatever property is required. All SoryByWhateverStrategy classes would then extend the base/abstract.