Created
February 22, 2013 18:55
-
-
Save giorgiosironi/5015697 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
{ | |
function __construct(Collaborator %collaborator) | |
{ | |
} | |
} | |
// vs. | |
class MyClass | |
{ | |
function doSomething(Collaborator $collaborator) | |
{ | |
} | |
} |
MyClass is composed by SomeHttpAction, which creates an implementation of Collaborator depending on some input parameter. SomeHttpAction and MyClass are created at the startup, while Collaborator is created after analyzing the request: that's why I find it handy to inject it as a parameter; from the point of view of MyClass nothing really changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah I get the idea, but what is the reason behind it?
Saving time by writing less constructor logic?
Or does MyClass have various methods and this one method requires an extra dependency that isn't injected using the construct?