Skip to content

Instantly share code, notes, and snippets.

Created June 21, 2013 21:19
Show Gist options
  • Save anonymous/5834419 to your computer and use it in GitHub Desktop.
Save anonymous/5834419 to your computer and use it in GitHub Desktop.
class Algorithm {
public:
void onEvent(Event x) {
this->strategy->onEvent(x);
}
protected:
Strategy* strategy;
std::vector<int> data;
}
class Strategy {
friend class Algorithm;
public:
Strategy(Algorithm& algo) : algo(algo) {};
virtual void onEvent(Event x) = 0;
protected:
Algorithm& algo; // Strategy needs to know Algorithm to modify its data
}
class ConcreteStrategy {
ConcreteStrategy(Algorithm& algo) : Strategy(algo) {}
virtual void onEvent(Event x) {
this->algo->data[...] = ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment