Consider the following implementation issues:
One approach is to have Context pass data in parameters to Strategy operations---in other words, take the data to the strategy. This keeps Strategy and Context decoupled. On the other hand, Context might pass data the Strategy doesn't need. Another technique has a context pass itself as an argument, and the strategy requests data from the context explicitly. Alternatively, the strategy can store a reference to its context, eliminating the need to pass anything at all. Either way, the strategy can request exactly what it needs. But now Context must define a more elaborate interface to its data, which couples Strategy and Context more closely.
The needs of the particular algorithm and its data requirements will determine the best technique.
The class is then configured with a Strategy class when it's instantiated:template class Context { void Operation() { theStrategy.DoAlgorithm(); } // ... private: AStrategy theStrategy; };
With templates, there's no need to define an abstract class that defines the interface to the Strategy. Using Strategy as a template parameter also lets you bind a Strategy to its Context statically, which can increase efficiency.class MyStrategy { public: void DoAlgorithm(); }; Context aContext;