Design Patterns Java - Strategy Php

1) What have we done?

For clarity we refactor code. We renamed the class "Context" into "ContextA1B1"

A1 - means that it implements method "doA" in version 1
B1 - means that it implements method "doB" in version 1
A2 - means that it implements method "doA" in version 2
B2 - means that it implements method "doB" in version 2


public class ContextA1B1
{
    public void doA()
    {
        System.out.println("DoingA version1");
    }

    public void doB()
    {
        System.out.println("DoingB version1");
    }
}




We created also two subclasses:


public class ContextA1B2 extends ContextA1B1
{
    public void doB()
    {
        System.out.println("DoingB version2");
    }
}

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

public class Client
{
    public static void main(String[] args)
    {
        ContextA1B1 contextA1B1 = new ContextA1B1();
        contextA1B1.doA();
        contextA1B1.doB();

        ContextA1B2 contextA1B2 = new ContextA1B2();
        contextA1B2.doA();
        contextA1B2.doB();

        ContextA2B1 contextA2B1 = new ContextA2B1();
        contextA2B1.doA();
        contextA2B1.doB();
    }
}




2) Is everything ok?

Theoretically yes, we can implement another version of this method, but let's see step3.