Design Patterns Java - Decorator Php

1) What have we done?

We have interface ParentA and its implementation ParentAImpl


public interface ParentA
{
    void doA();
}

public class ParentAImpl implements ParentA
{
    public void doA()
    {
        System.out.println("Doing A");
    }
}




By analogy ParentB and ParentBImpl


public interface ParentB
{
    void doB();
}

public class ParentBImpl implements ParentB
{
    public void doB()
    {
        System.out.println("Doing B");
    }
}




The "Child" class(our "Decorator") implements interface "ProductA" in order to be transparent to Client (the type of Child must be the same as ProductA)
We achieve this interface by aggregating "ProductAImpl"

"Child" class inherits also after "ProductBImpl" in order to use its implementation.

In the other words "Child" decorating "ProductAImpl" means adds addition implementation.

public class Child extends ParentBImpl implements ParentA
{
    private ParentA parentA;

    public Child(ParentA parentA)
    {
        this.parentA = parentA;
    }

    public void doA()
    {
        parentA.doA();
    }
}




In method "doA" in "Child" class we could easily besides call method "doA" add some other code. So we could decorating by adding another methods like here from
ProductBImpl but also we can modify behaviour of decorated object.


2) What is the final result ?

The final result is exactly the same as we want. Used in "Child" class both implementation od "ProductAImpl" as "ProductBImpl".