I am doing the design of a small project where I didn’t use programming against interfaces for all my classes. I found that some classes would hardly ever be needed to change, so I let them be referenced by their client classes as concrete classes.
So, let’s say we have ClassB that’ll be consumed be consumed by ClassA:

class ClassB {
}
My question is, should I create ClassB in ClassA, or should I pass that responsability “up” in the hierarchy? I’ll depict both cases:
class ClassA {
private ClassB classB;
public ClassA() {
this.classB = new ClassB();
}
}
or
class ClassA {
private ClassB classB;
public ClassA(ClassB classB) {
this.classB = classB;
}
}
I’d like to hear about how would you do it and what’d be the rationale behind it!
Thanks
Some advantages of your first option (A creates B):
Some advantages of your second option (A takes a dependency on B):
Note that it is also possible to create a “best of both worlds” solution by using what is sometimes called “poor man’s dependency injection”: