Design Patterns Java - Template method Php

1) What have we done?

We just created abstract class "AbstractClass" and implemented there whole algorithm.


public abstract class AbstractClass
{
    public void doSomething(boolean doStep2)
    {
        doStep1();
        if (doStep2)
        {
            doStep2();
        }
        doStep3();
    }

    protected abstract void doStep1();

    protected abstract void doStep2();

    protected abstract void doStep3();
}

public class ClassA extends AbstractClass
{
    @Override
    protected void doStep1()
    {
        System.out.println("ClassA doing step one");
    }

    @Override
    protected void doStep2()
    {
        System.out.println("ClassA doing step two");
    }

    @Override
    protected void doStep3()
    {
        System.out.println("ClassA doing step three");
    }
}

public class ClassB extends AbstractClass
{
    @Override
    protected void doStep1()
    {
        System.out.println("ClassB doing step one");
    }

    @Override
    protected void doStep2()
    {
        System.out.println("ClassB doing step two");
    }

    @Override
    protected void doStep3()
    {
        System.out.println("ClassB doing step three");
    }
}




In subclasses we implement particular steps now we don't have any duplication.