Skip to content

Improve code related to Factory design pattern #76

Description

@simatic

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions