Design Patterns Java - Strategy Php

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


public class ContextA2B2 extends ContextA1B2
{
    public void doA()
    {
        System.out.println("DoingA version2");
    }
}




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.