version A:
class A
{
private $b, $c, $d, $e;
public function __constructor (B $b, C $c, D $d, E $e)
{
$this->b = $b;
$this->c = $c
.
.
.
}
}
class B
{
}
class C
{
}
class D
{
}
I heard many times that application should not be aware of DI container itself. Well, then this is the clearest sollution, but requires tons of codes which is unrelated to class A itself, and has to be modified whenever another object is must be reached. Version 2:
class Container
{
public function getB()
{
return new B();
}
public function getC()
{
return new C();
}
.
.
.
}
class A
{
private $container;
public function __constructor(Container $container)
{
$this->container = $container;
}
}
this is shorter but this time Container it tightly coupled. Plus, if there are 10000 objects in Container, Im not sure its a good approact to reach them all...
which way to go?