Design Patterns Java - Facade Php

1) At the beginning

Let's imagine that we have three following classes.


public class ClassA
{
    private String a;

    public ClassA(String a)
    {
        this.a = a;
    }

    public void doA()
    {
        a += " doing A";
    }

    public String getA()
    {
        return a;
    }
}

public class ClassB
{
    private String b;

    public void doB()
    {
        b += " doing B ";
    }

    public String getB()
    {
        return b;
    }

    public void setB(String b)
    {
        this.b = b;
    }
}

public class ClassC
{
    private String c;

    public void doC(ClassB b)
    {
        c = b.getB() + " doing C with B";
    }

    public String getC()
    {
        return c;
    }
}




Yes this logic and relations between objects are really messy

2) And imagine Client


public class Client
{
    public static void main(String[] args)
    {
        ClassA a = new ClassA("something");
        ClassB b = new ClassB();
        ClassC c = new ClassC();

        a.doA();
        b.setB(a.getA());
        b.doB();
        c.doC(b);

        String desirableObject = c.getC();
    }
}




3) What is wrong with client?

As we see, client has to use quite messy and complicated interface of subsystems(ClassA, ClassB, ClassC) in order to receive desirable object.