OK, I am creating a small PHP application. The current structure looks something like this:
$client = new AppName\Client;
$model = $client->getModel();
$model->getNode();
Everything is beautiful here. The client is responsible for connecting and running commands through Socket for the small C application that I created. I just play with architecture here. Client :: getModel returns an instance of the model. During getModel, I inject Client inside Model through the constructor. Something like that:
public function getModel()
{
return new Model('parameter', $this);
}
Which in turn...
public function __construct($param, Client $client)
{
$this->setClient($client);
}
However, during Model :: getNode, I want to return an instance of Node. However, unlike getModel, I do not want to enter the Client again. But I need to. Right now, I'm doing this:
public function getNode()
{
return new Node('parameter', $this->getClient());
}
, . -, ... Injection Dependency, , Dependency .