Design Patterns Java - Chain of responsibility Php

1) What we have done?

Because code of passing "Request" for the next "Handler" is the same for every "Handler" object.
We just move this to the parent abstract "Handler" class


public abstract class Handler
{
    protected Handler next;

    public void setNext(Handler next)
    {
        this.next = next;
    }

    public void handleRequest(Request request)
    {
        if (canHandle(request))
        {
            innerHandle(request);
        }
        else if (next != null)
        {
            next.handleRequest(request);
        }
    }

    protected abstract boolean canHandle(Request request);

    protected abstract void innerHandle(Request request);
}

public class HandlerA extends Handler
{
    @Override
    protected boolean canHandle(Request request)
    {
        return request.getAttribute().equals("handlerA");
    }

    @Override
    protected void innerHandle(Request request)
    {
        System.out.println("HandlerA doing something with request");
    }
}

public class HandlerB extends Handler
{
    @Override
    protected boolean canHandle(Request request)
    {
        return request.getAttribute().equals("handlerB");
    }

    @Override
    protected void innerHandle(Request request)
    {
        System.out.println("HandlerB doing something with request");
    }
}