Design Patterns Java - Dependency Injection Php

1) Let's consider the following code


public class ClassA
{
    private ClassB classB = new ClassB();

    private String one = "A1";

    private String two = "A2";
}

public class ClassB
{
    private String one = "B1";

    private String two = "B2";
}




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


public class Client
{
    public static void main(String[] args)
    {
        ClassA a = 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.