mercredi 26 mai 2021

Desing pattern for two inputs?

First of all, I had task 1 and it was about rest API, requesting calls using httpclient in order to use the functions of an API. We get an input from a user, either "Online" or "Offline". If it is an "Online", we request calls such as generating tokens, and we display the result on GUI using javafx or swing. If the input is "Offline", we just request calls from a mocked API that I personally made so that the program can be run even if the server is down or the internet is cut off. I used a facade pattern here in order to flexibly and simply change in between online and offline.

In the main method, it goes like this:

if(input == "online") {
    facade.online();
} else if (input == offline) {
    facade.offline();
}

The second one is the extension of task 1. They are similar to each other but the thing is, we get two inputs in which they are, the first one is the same as the one in task 1, but the second input is for the output of the result. For example, saying that we have A and B APIs and we get information/data from A by requesting calls, then we output the result through the B API (B can be an api like a pastebin, which we can save the result by creating a note on the pastebin site). If the second input is "Offline", we just save the result on a notepad.

I need to keep the facade pattern here, but what kind of design pattern should I apply in order to cover the second input as well?

I am thinking of using Factory or Strategy pattern for it, and am doing some researches for that, but still not getting ideas of how to collaborate facade with factory or strategy pattern...

Thanks.

Aucun commentaire:

Enregistrer un commentaire