Steve - 2015-11-03 11:54:02 - In reply to message 1 from steven
Was interested in the article, though missing the explanation of the 'basics' - much like the start of the movie "The Martian" - several holes in the story, like the explanation of why the crew would go 'exploring' during a storm so intense they had to leave Mars......
Kayla Anderson - 2015-11-03 12:43:50 - In reply to message 1 from steven
I'm glad it wasn't just me. I read it and it sounded like "Dependency injection is about injecting dependencies and it's useful because it injects dependencies. Here's some code that shows you how to set a property on a class."
Samuel Adeshina - 2015-11-03 19:32:04 - In reply to message 3 from Kayla Anderson
Think of an instance where you want to create a database query class (or service)
You need to provide a connection to your database, this is what the query class uses to "make the necessary connections to the DB and executes queries successfully". Usually, a separate class handles the connection.
You can pass your connection class into your query class as a dependency, in other words, you inject the connection class (the dependency, a service or factory needed by other objects or services) into your query class which is the object that's dependent on another object.
public function conn()
//perform connections to the database
public function __construct(connection $connObj)
//we've just established a connection to the DB
The above code snippet is a better illustration of the DI concept. Think of the connection class as the "automobile object" and the query class as the "car object" for a "car class" analogy.
Watch out for the next part of the article that talks about how to properly inject objects, more on the single responsibility principle and how to build a DI container like Pimple.