Let me show several classes firstly:
class globalcontext
{
public:
/*partA context*/
A;
B;
c;
/*partB context*/
D;
E;
F;
.......
execute(); //a method to do something (serialize) for context above
};
class mainprocess
{
callsubprocess();
};
class subprocessA{};
class subprocessB{};
class subprocessC{};
..................
Actually, there are several backends running the main process, so the context will be sent from here or there, that’s why I want to execute(serialize/unserialize).
The flow is like: mainprocess::callsubprocess() —-> choose a subprocess, so choose subprocessA—-> execute partA of context from globalcontext class.
Is it possible to use factory in boost?
Maybe you are looking for a strategy pattern? Assuming that A-F encode behaviour, you could ‘mixin’ different behaviours or supply them as strategies:
Note: below, the separation between static/non-static member functions is a little bit arbitrary (mixins can perfectly well contain static members).
Mixins
Output http://liveworkspace.org/code/b6b5cfffba11df68bc70c432b030b1d5
Strategy
Output http://liveworkspace.org/code/8bca96d0e9784026c6357a30110bc5fd