jeudi 7 avril 2016

Chaining of responsibility pattern takes different parameter types?

I've read the chain of the responsibility pattern, the examples are nothing but normal printing. What if I'd like to chaining more difficult operations together, for instance, there's some use case in real life:

Taking a request, request -> Handler 1 (request, Integer) -> Handler 2 (Integer, String) -> Handler 3 (String, Long),

in which each handler takes some input of parameter, and generate output in another parameter type. Can we chain such handlers together using Generic idea?

public abstract class Handler <Input, Output> {
    public void setSuccessor(Handler handler);
    public abstract Output handleRequest(Input in);
}

I hope I clarify the problems clearly enough. Thanks!

Aucun commentaire:

Enregistrer un commentaire