turtle
turtle copied to clipboard
How to provide alternatives in sequence
Suppose I have the following class:
struct Foo{
virtual void before();
virtual void do();
virtual void after();
};
With the sequence approach I can make sure, those functions are called in order when having a single instance.
But what do I do when I have multiple instances? Example:
Foo* f1 = new Foo;
Foo* f2 = new Foo;
container.add(f1, f2);
// Expect (f1.before && f2.before) + (f1.do && f2.do) + (f1.after && f2.after)
container.process();
How can I ensure, that both before are called first, then both do etc while the order of the calls to the same function do not matter?
You probably need to use several sequences for that, which I admit is a little cumbersome…
Something like:
- s1 : f1.before -> f1.do
- s2 : f1.before -> f2.do
- s3 : f2.before -> f1.do
- s4 : f2.before -> f2.do
etc…