You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dependency-injection/README.md
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -9,27 +9,32 @@ tags:
9
9
---
10
10
11
11
## 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.
16
18
17
19
## Explanation
20
+
18
21
Real world example
19
22
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.
21
25
22
26
In plain words
23
27
24
28
> Dependency Injection separates creation of client's dependencies from its own behavior.
25
29
26
30
Wikipedia says
27
31
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.
29
34
30
35
**Programmatic Example**
31
36
32
-
Let's first introduce the tobacco brands.
37
+
Let's first introduce the `Tobacco` interface and the concrete brands.
33
38
34
39
```java
35
40
publicabstractclassTobacco {
@@ -52,7 +57,7 @@ public class OldTobyTobacco extends Tobacco {
52
57
}
53
58
```
54
59
55
-
Next here's the wizard class hierarchy.
60
+
Next here's the `Wizard` class hierarchy.
56
61
57
62
```java
58
63
publicinterfaceWizard {
@@ -83,13 +88,15 @@ And lastly we can show how easy it is to give the old wizard any brand of tobacc
0 commit comments