A
Angus
I am trying to set the strategy (algorithm) used in a context by
template. Here is my context class (which is incorrectly
implemented):
template <class TStrategy>
class Context //TStrategy is the algorithm
{
private:
TStrategy * strategy_; //knows about StrategyInterface
public:
void execute() const
{
strategy_->execute();
}
};
The strategies:
class StrategyInterface
{
public:
virtual void execute() const = 0; //abstract class - interface
only
};
//the actual concrete algorithms
class ConcreteStrategyA: public StrategyInterface
{
public:
virtual void execute() const
{
cout << "Called ConcreteStrategyA execute method" << endl;
}
};
And I want to do something like this:
Context<ConcreteStrategyA> contextD;
contextD.execute();
But I need to initialise the context data member properly. how do I
do that?
Angus
template. Here is my context class (which is incorrectly
implemented):
template <class TStrategy>
class Context //TStrategy is the algorithm
{
private:
TStrategy * strategy_; //knows about StrategyInterface
public:
void execute() const
{
strategy_->execute();
}
};
The strategies:
class StrategyInterface
{
public:
virtual void execute() const = 0; //abstract class - interface
only
};
//the actual concrete algorithms
class ConcreteStrategyA: public StrategyInterface
{
public:
virtual void execute() const
{
cout << "Called ConcreteStrategyA execute method" << endl;
}
};
And I want to do something like this:
Context<ConcreteStrategyA> contextD;
contextD.execute();
But I need to initialise the context data member properly. how do I
do that?
Angus