jeudi 12 mai 2022

Separate request building and execution

I have a few kinds of requests that have different payloads (or no payload at all). I want to separate request building from its execution, so I have RequestFactory that produces abstract Request and RequestExecutor that has method execute(request). The problem is that logic of request execution is coupled with its type, so I would need to have cases like this:

if(request instanceof SomeTypeOfRequest) ((SomeTypeOfRequest) request).getPayload()

Another approach is to have execute method inside Request but that leads to having all of RequestExecutor dependencies inside RequestFactory as I need them to build a request. What other options do I have?

Aucun commentaire:

Enregistrer un commentaire