Design Patterns PHP - Dependency Injection Java

1) Let's consider the following code


class ClassA
{

    /**
     * @var ClassB
     */
    private $classB;

    /**
     * @var String
     */
    private $one = 'some A1 initial value';

    /**
     * @var String
     */
    private $two = 'some A2 initial value';

    /**
     * ClassA constructor.
     */
    public function __construct()
    {
        $this->classB = new ClassB();
    }

}

class ClassB
{
    /**
     * @var String
     */
    private $one = 'some B1 initial value';

    /**
     * @var String
     */
    private $two = 'some B2 initial value';
}




And we need some objects of A in application, so it's very easy, lets create it


$classA = new ClassA();




Is it ok ? Yes, it's very easy to create objects of "A", we have hardcoded all fields of "A" two strings and also hardcoded "B" instance there by
also we have hardcoded two fields of "B". "A" and "B" are tightly coupled. But it's ok as long as we always need objects of "A" with invariable values.

3) What we want to change ?

It turned out that fields "one" and "two" must be changeable. We just want to create objects of "A" and "B" with different parameters.

Nothing complicated, So let's go refactor this code.