Home > Net >  Separate request building and execution
Separate request building and execution

Time:05-16

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?

CodePudding user response:

It seems like I can use visitor. It sort of combines this two approaches. I just need to have execute(RequestExecutor) method in Request interface

  • Related