vendredi 11 octobre 2019

Return an Async and Sync client from Build

I'm new to java design patterns and I'm trying to set up a build method that either returns an async client if the boolean isAsync is true and a sync client otherwise

public DGraphClient build() {
    if (isAsync) {
        return AsyncDGraphJavaClient.getInstance(host,port,user,pass);
    }
    return DGraphJavaClient.getInstance(host,port,user,pass);
}

This is what I would like my logic to be, but the two returns are not of the same type (one is an async client and the other a sync client). How can I accomplish what I want?

Aucun commentaire:

Enregistrer un commentaire