Design Patterns PHP - Template method Java

1) What have we done?

We just created class "ClassB". We changed there step3.

class ClassA
{
    /**
     * @param boolean $doStep2
     */
    public function doSomething($doStep2)
    {
        echo 'doing step one' . PHP_EOL;
        if ($doStep2)
            echo 'doing step two' . PHP_EOL;
        echo 'doing step three' . PHP_EOL;
    }
}

class ClassB extends ClassA
{
    /**
     * @param boolean $doStep2
     */
    public function doSomething($doStep2)
    {
        echo 'doing step one' . PHP_EOL;
        if ($doStep2)
            echo 'doing step two' . PHP_EOL;
        echo 'doing changed step three' . PHP_EOL;
    }
}

$object = new ClassB();
$object->doSomething(true);



2) Why is this wrong?

We we can see we have duplication of code in "ClassA" and "ClassB"

The whole algorithm is unchanged there is only changed step 3.

3) How we can improve this?

We can apply "Template Method" pattern means implement template method responsible for algorithm and implementation of particular steps move to subclasses.