Setup:
It is necessary to create a pseudo-random structure. There are several methods / algorithms available for creating other content. All algorithms will generate a list of characters (but maybe something else) ... the important part is that they all return the same type of values โโand need the same type of input arguments.
It should be possible to call the GetRandomPattern () method, which will use a random one of the algorithms each time it is called.
My first approach was to put each algorithm in its own function and select a random one each time GetRandompattern () is called. But I did not come up with a different way of choosing between them, and not with the expression of the switch statement, which is uncomfortable, ugly and inflexible.
class PatternGenerator{ public: list<char> GetRandomPattern(); private: list<char>GeneratePatternA(foo bar); list<char>GeneratePatternB(foo bar); ........ list<char>GeneratePatternX(foo bar); }
What would be a good way to select a random GeneratePattern function each time the GetRandomPattern () method is called?
Or should the whole class be designed differently?
Thank you so much
c ++ design-patterns random function-pointers
zitroneneis
source share