-
-
Save Fiona-J-W/5834452 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
template<Strategy> | |
class Algorithm { | |
friend class ConcreteStrategy; | |
public: | |
Algorithm(ConcreteStrategy strategy) : strategy{strategy} { | |
strategy.set_algorithm(this); | |
} | |
void onEvent(Event x) { | |
this->strategy.onEvent(x); | |
} | |
protected: | |
ConcreteStrategy strategy; | |
std::vector<int> data; | |
}; | |
/// ///////////////////////////////// | |
class ConcreteStrategy { | |
friend class Algorithm<ConcreteStrategy>; | |
void set_algorithm(Algorithm<ConcreteStrategy>* algo){this->algo = algo;} | |
public: | |
ConcreteStrategy() : algo{nullptr} {} | |
void onEvent(Event x) { | |
this->algo->data[...] = ... | |
} | |
private: | |
Algorithm<ConcreteStrategy> * algo; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment