vendredi 29 novembre 2019

Is there a Design Pattern that solve this problem?

2 (+1) Requirements

1.- The user must be able to add many types of Equipment
2.- When the type of equipment is "SOME VALUE" then ...
N.- ... future requirement ... now when the type of equipment is "SOME OTHER VALUE" then ...

The situation is that in one side, I know that the "Types" could change, but also I know that some values must exist particular values of "Type" in order to perform particular behaviors.

private int SomeAction(Equipment e)
{
    if (e.Type == "SOME VALUE")
    {
        // Do something for that special case
    }
    else if (e.Type == "SOME OTHER VALUE")
    {
        // Do something for that other special case
    }
    else
    {
        // Do the other thing
    }
}

Aucun commentaire:

Enregistrer un commentaire