This is the correct template, in my opinion, I often use it.
Enabling dependencies allows the class user to provide dependencies. With your code, this is possible, so I do not see a problem with it.
The only thing I do differently is that I use explicit parameters so that I can type fonts, hint at objects, make sure they have the correct class, and make it easier to know which parameters can be passed without code search:
class Car { private $engine; public function __construct(Engine $engine = null) { $this->engine = $engine ?: new Engine(); } }
source share