Design Patterns PHP - Strategy Java

1) What have we done?

We add another class "ContextA2B2" which implements method "doA" and "doB" in version 2

We can inherit from "ContextA1B2" or "ContextA2B1" but anyway we are forced for write the same code two times.

We can't omit this


class ContextA2B2 extends ContextA1B2
{
    public function doA()
    {
        echo 'DoingA ver2' . PHP_EOL;
    }
}




Let's imagine that we have many versions, more methods. Unfortunately given solution becomes nightmare.

2) What can we do?

We can move behaviour of methods to separate interfaces. This is "Strategy" pattern

Let's see this in step4.