Em Ae
Em Ae

Reputation: 8724

Is there a specific name to following pattern?

I designed a framework to expose some rest based webservices. The base classes looked like this (not exact code)

public interface WSService {
    public void init(WSRequest request);
    public List<String> validate();
    public void performAction();
    public WSResponse generateResponse();
}

Each new service, implements this webservice and implements its specific logic

public class WSOrders implements WSService {...}

Then, i implemented a WSProcessor which takes in specific class and then execute the methods and performs error checks/etc. for example

@RestResource(GET, "/getorders")
public Response getOrders (...){
    WSService getOrders = new WSOrders();
    WSRequestProcessor processor = new WSRequestProcessor(restInput);
    processor.process(getOrders);    
}

in WSRequestProcessor, i used the process method to first extract input from rest request, do application level validation (some headers validation etc). Then called metthods like this

public WSRequestProcessor{
...

    public void process (WSService service){
        service.init()
        service.validate();
        service.performAction();
        service.generateResponse();
    }
}

One thing to note that WSRequestProcessor handles all the exception handling, generic error response creation etc.

This pattern worked out pretty well to expose any of the resource for us. At the end of the day, to expose any resource, all i had to (or any developer) was to create WS<ResourceName> and implement their business logic there.

Upvotes: 0

Views: 20

Answers (1)

Thatalent
Thatalent

Reputation: 424

At first this seems like just basic polymorphism, though I see why you would want to know if there is a design pattern that this could be referred to as. I would first say that this is loosely SOLID design and then say that there is a basic form of a facade pattern for how the getOrders method is designed and then maybe a Command pattern.

Upvotes: 1

Related Questions