Design Patterns Java - Decorator Php

1) What do we have ?

We have two classes implementing some functionality.

class "ParentA" - implements "doA"
and class "ParentB" implements "doB"



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

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




2) What want we to achieve ?

We want to use in "Child" class both implementation of "ParentA" alike implementation of "ParentB"

Let's look on class "Child"


public class Child extends ParentA//, ParentB
{
}




Unfortunately/fortunately there is no possible multiple inheritance

2) How can we achieve our goal ?

We create interface which defining "doA" so the class "ParantA" implements this interface

"Child" class will implement the same interface, we aggregate into it object of "ParentA" and with this object we will implement interface "ParentA".

And all other methods we easily can modify lub add new, so in the other words we will decorate "ParentA" with class "ParentB"