SimaticResearchActivity / FBAE

Framework for Broadcast Algorithms Evaluation
GNU Affero General Public License v3.0
0 stars 1 forks source link

Improve code related to Factory design pattern #76

Open simatic opened 4 months ago

simatic commented 4 months ago

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.