mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-17 19:16:20 +02:00
Fix DI typo
This commit is contained in:
@@ -4,10 +4,10 @@ isChild: true
|
|||||||
|
|
||||||
## Basic Concept {#basic_concept_title}
|
## Basic Concept {#basic_concept_title}
|
||||||
|
|
||||||
We can demonstrate the concept with a simple, yet naive.
|
We can demonstrate the concept with a simple, yet naive example.
|
||||||
|
|
||||||
Here we have a `Database` class that requires an adapter to speak to the database. We instantiate the
|
Here we have a `Database` class that requires an adapter to speak to the database. We instantiate the
|
||||||
adapter in the constructor and create a hard dependency. This makes testing difficult and means the `Database` class is
|
adapter in the constructor and create a hard dependency. This makes testing difficult and means the `Database` class is
|
||||||
very tightly coupled to the adapter.
|
very tightly coupled to the adapter.
|
||||||
|
|
||||||
{% highlight php %}
|
{% highlight php %}
|
||||||
@@ -46,6 +46,6 @@ class Database
|
|||||||
class MysqlAdapter {}
|
class MysqlAdapter {}
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
Now we are giving the `Database` class it's dependency rather than it creating it itself. We could even create a method
|
Now we are giving the `Database` class it's dependency rather than it creating it itself. We could even create a method
|
||||||
that would accept an argument of the dependency and set it that way, or if the `$adapter` property was `public` we could
|
that would accept an argument of the dependency and set it that way, or if the `$adapter` property was `public` we could
|
||||||
set it directly.
|
set it directly.
|
||||||
|
Reference in New Issue
Block a user