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: strategy/README.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,18 @@ Policy
16
16
## Intent
17
17
18
18
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets
19
-
the algorithm vary independently from clients that use it.
19
+
the algorithm vary independently from the clients that use it.
20
20
21
21
## Explanation
22
22
23
-
Realworld example
23
+
Real-world example
24
24
25
-
> Slaying dragons is a dangerous job. With experience it becomes easier. Veteran
25
+
> Slaying dragons is a dangerous job. With experience, it becomes easier. Veteran
26
26
> dragonslayers have developed different fighting strategies against different types of dragons.
27
27
28
28
In plain words
29
29
30
-
> Strategy pattern allows choosing the bestsuited algorithm at runtime.
30
+
> Strategy pattern allows choosing the best-suited algorithm at runtime.
31
31
32
32
Wikipedia says
33
33
@@ -36,7 +36,7 @@ Wikipedia says
36
36
37
37
**Programmatic Example**
38
38
39
-
Let's first introduce the dragonslaying strategy interface and its implementations.
39
+
Let's first introduce the dragon-slaying strategy interface and its implementations.
40
40
41
41
```java
42
42
@FunctionalInterface
@@ -73,7 +73,7 @@ public class SpellStrategy implements DragonSlayingStrategy {
73
73
}
74
74
```
75
75
76
-
And here is the mighty dragonslayer, who is able to pick his fighting strategy based on the
76
+
And here is the mighty dragonslayer, who can pick his fighting strategy based on the
77
77
opponent.
78
78
79
79
```java
@@ -95,7 +95,7 @@ public class DragonSlayer {
95
95
}
96
96
```
97
97
98
-
Finally here's the dragonslayer in action.
98
+
Finally, here's the dragonslayer in action.
99
99
100
100
```java
101
101
LOGGER.info("Green dragon spotted ahead!");
@@ -120,7 +120,7 @@ Program output:
120
120
You cast the spell of disintegration and the dragon vaporizes in a pile of dust!
121
121
```
122
122
123
-
What's more, the new feature Lambda Expressions in Java 8 provides another approach for the implementation:
123
+
What's more, the lambda expressions in Java 8 provides another approach for the implementation:
124
124
125
125
```java
126
126
publicclassLambdaStrategy {
@@ -163,7 +163,7 @@ And here's the dragonslayer in action.
163
163
dragonSlayer.goToBattle();
164
164
```
165
165
166
-
Program output is the same as above one.
166
+
The program output is the same as the above one.
167
167
168
168
## Class diagram
169
169
@@ -175,8 +175,8 @@ Use the Strategy pattern when
175
175
176
176
* Many related classes differ only in their behavior. Strategies provide a way to configure a class either one of many behaviors
177
177
* You need different variants of an algorithm. for example, you might define algorithms reflecting different space/time trade-offs. Strategies can be used when these variants are implemented as a class hierarchy of algorithms
178
-
* An algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures
179
-
* A class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class
178
+
* An algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex algorithm-specific data structures
179
+
* A class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move the related conditional branches into their own Strategy class
0 commit comments