@HRcc why do you call Service Containers IOC Containers?
@thepsion5 I am not understanding your response. The reason for an interface is to force the coding of the interface methods within each implementation. Each implementation would handle the interface methods the same or slightly different depending on the media it is using. @pmall's examples cited emails, SMS texts and several others, based upon the common interface.
I agree that if you changed the __constructor parameters then you would have to track down all instances within the code base in order to update them. Thus you are saying create a Service Container for these implementations so that if dependencies change then all you change is the Service Container declaration?
So how does the following example from @pmall pass a Bar object into class Foo?
class Foo
{
public function __construct(Bar $bar) {}
}
$foo = app('Foo'); // Bar wil be injected even if Foo is registered nowhere
@martinbean I am looking for specific examples in order to understand. Using general declaratives is not working as I am not building the relationships in my mind in order to understand. It would be helpful if we had a whiteboard where all this could be diagrammed for me.
Your description is valid, however I have to write all these objects and cannot if I don't understand the architecture and relationships of the objects. I understand that your geo services are all based upon a common interface, but I am not seeing how the Service Container is creating the object when you use the following syntax
$Foo = app('foo');
And the Foo class has a Baz object dependency that must be injected at creation. In older syntax
$Foo = new Foo(new Baz()) ;
would work. So how does the Service Container get the Baz into the Foo?