Skip to content

Commit 8afe4c3

Browse files
committed
Update README.md
1 parent 2dd2cfb commit 8afe4c3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

dependency-injection/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@ tags:
99
---
1010

1111
## Intent
12-
Dependency Injection is a software design pattern in which one or more dependencies (or services) are injected, or
13-
passed by reference, into a dependent object (or client) and are made part of the client's state. The pattern separates
14-
the creation of a client's dependencies from its own behavior, which allows program designs to be loosely coupled and
15-
to follow the inversion of control and single responsibility principles.
12+
13+
Dependency Injection is a software design pattern in which one or more dependencies (or services)
14+
are injected, or passed by reference, into a dependent object (or client) and are made part of the
15+
client's state. The pattern separates the creation of a client's dependencies from its own behavior,
16+
which allows program designs to be loosely coupled and to follow the inversion of control and single
17+
responsibility principles.
1618

1719
## Explanation
20+
1821
Real world example
1922

20-
> The old wizard likes to fill his pipe and smoke tobacco once in a while. However, he doesn't want to depend on a single tobacco brand only but likes to be able to enjoy them all interchangeably.
23+
> The old wizard likes to fill his pipe and smoke tobacco once in a while. However, he doesn't want
24+
> to depend on a single tobacco brand only but likes to be able to enjoy them all interchangeably.
2125
2226
In plain words
2327

2428
> Dependency Injection separates creation of client's dependencies from its own behavior.
2529
2630
Wikipedia says
2731

28-
> In software engineering, dependency injection is a technique in which an object receives other objects that it depends on. These other objects are called dependencies.
32+
> In software engineering, dependency injection is a technique in which an object receives other
33+
> objects that it depends on. These other objects are called dependencies.
2934
3035
**Programmatic Example**
3136

32-
Let's first introduce the tobacco brands.
37+
Let's first introduce the `Tobacco` interface and the concrete brands.
3338

3439
```java
3540
public abstract class Tobacco {
@@ -52,7 +57,7 @@ public class OldTobyTobacco extends Tobacco {
5257
}
5358
```
5459

55-
Next here's the wizard class hierarchy.
60+
Next here's the `Wizard` class hierarchy.
5661

5762
```java
5863
public interface Wizard {
@@ -83,13 +88,15 @@ And lastly we can show how easy it is to give the old wizard any brand of tobacc
8388
```
8489

8590
## Class diagram
91+
8692
![alt text](./etc/dependency-injection.png "Dependency Injection")
8793

8894
## Applicability
89-
Use the Dependency Injection pattern when
9095

91-
* When you need to remove knowledge of concrete implementation from object
92-
* To enable unit testing of classes in isolation using mock objects or stubs
96+
Use the Dependency Injection pattern when:
97+
98+
* When you need to remove knowledge of concrete implementation from object.
99+
* To enable unit testing of classes in isolation using mock objects or stubs.
93100

94101
## Credits
95102

0 commit comments

Comments
 (0)