Created
June 21, 2013 21:19
-
-
Save anonymous/5834419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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