dimanche 8 mai 2016

Configuring the order of method execution

I have an api client that is able to make calls to 4 different endpoints. I am running into an issue where i am trying to make it as configurable as possible since each api calling method is independent of the other. So, I would like to leave the order in which they can be called flexible. Here is what I mean:

public class APICaller () {
    public void endpointA () {...
    }

    public void endpointB () {...
    }

    public void endpointC () {...
    }

    public void endpointD () {...
    }
}

I have tried to do this by passing in an array of an Endpoint enum(A,B,C,D) and then iterating over the contents of the array and calling the related method using a switch statement:

for (Endpoint end : passedInArrayOfOrdering) {
    switch(end) {
        case A:
            endpointA();
        ...
    }
}

My above attempt seems a little dirty to me. Is there an existing pattern that lets me configure the order in which to make these endpoint calls?

Aucun commentaire:

Enregistrer un commentaire