Skip to content
Advertisement

Php, is it OK to use traits for DI?

consider this example:

JavaScript

so far so simple (apart from injected is not injected). So, in full version:

JavaScript

but I find it enoromous. Why to pollute my class with tons of code of DI? Lets split this into two entities:

JavaScript

its much nicer although I never seen anybody using it like this. Is it a good approach?

Advertisement

Answer

For example like this:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement