Skip to content

Instantly share code, notes, and snippets.

@Fiona-J-W
Forked from anonymous/gist:5834419
Last active December 18, 2015 19:39
Show Gist options
  • Save Fiona-J-W/5834452 to your computer and use it in GitHub Desktop.
Save Fiona-J-W/5834452 to your computer and use it in GitHub Desktop.
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