Current fbae implements Factory design pattern by explicitely having two functions in main.cpp to decide which object should be created. For instance, the creation of a concrete AlgoLayer is implemented with the following code:
unique_ptr<AlgoLayer> concreteAlgoLayer(OptParserExtended const &parser)
{
char algoId = parser.getoptStringRequired('a')[0];
switch(algoId)
{
case 'S': return make_unique<Sequencer>(concreteCommLayer(parser));
case 'B' : return make_unique<BBOBB>(concreteCommLayer(parser));
case 'L' : return make_unique<LCR>(concreteCommLayer(parser));
default:
std::cerr << "ERROR: Argument for Broadcast Algorithm is " << algoId
<< " which is not the identifier of a defined algorithm"
<< std::endl
<< parser.synopsis () << std::endl;
exit(EXIT_FAILURE);
}
}
Thus, when a new algorithm is implemented, programmer must thing about adding a case in the hereabove switch. It would be cleaner to implement a Factory template to which each algorithm would spontaneously subscribe.
Current
fbae
implements Factory design pattern by explicitely having two functions inmain.cpp
to decide which object should be created. For instance, the creation of a concreteAlgoLayer
is implemented with the following code:Thus, when a new algorithm is implemented, programmer must thing about adding a
case
in the hereaboveswitch
. It would be cleaner to implement aFactory
template to which each algorithm would spontaneously subscribe.