Disciplined Agile

Chain of Reponsibility Pattern Generics Impl

interface CoR
{
    public string operation(string data);
}

class ChainA<T> : CoR where T : class , CoR
{
    protected CoR myNextCoR;
    public string operation(string data)
    {
        if (isMyOperation(data))
        {
            return myOperation(data);
        }
        if (T != null) return myNextCoR.operation(data);
        return "no operation found";

    }
     protected override bool isMyOperation(string data)
     {
        return data.StartsWith("1");
    }
    protected override string myOperation(string data)
    {
        return data.ToUpper();
    }
}

class ChainB<T> : CoR where T : CoR, class
{
    protected CoR myNextCoR;
    public string operation(string data)
    {
        if (isMyOperation(data))
        {
            return myOperation(data);
        }
        if (T != null) return myNextCoR.operation(data);
        return "no operation found";

    }
     protected override bool isMyOperation(string data)
     {
        return data.StartsWith(“2");
    }
    protected override string myOperation(string data)
    {
        return data.ToLower();
    }
}

class CorFactory
{
    public static CoR makeCoR()
    {
        return  new ChainA<ChainB<ChainEnd>>(
            new ChainB<null>());
    }
}