Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Grammar fixes for strategy
  • Loading branch information
iluwatar committed Jun 22, 2021
commit 808df54dc0264a130fe6a0ac8f068aa47c053858
22 changes: 11 additions & 11 deletions strategy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ Policy
## Intent

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets
the algorithm vary independently from clients that use it.
the algorithm vary independently from the clients that use it.

## Explanation

Real world example
Real-world example

> Slaying dragons is a dangerous job. With experience it becomes easier. Veteran
> Slaying dragons is a dangerous job. With experience, it becomes easier. Veteran
> dragonslayers have developed different fighting strategies against different types of dragons.

In plain words

> Strategy pattern allows choosing the best suited algorithm at runtime.
> Strategy pattern allows choosing the best-suited algorithm at runtime.

Wikipedia says

Expand All @@ -36,7 +36,7 @@ Wikipedia says

**Programmatic Example**

Let's first introduce the dragon slaying strategy interface and its implementations.
Let's first introduce the dragon-slaying strategy interface and its implementations.

```java
@FunctionalInterface
Expand Down Expand Up @@ -73,7 +73,7 @@ public class SpellStrategy implements DragonSlayingStrategy {
}
```

And here is the mighty dragonslayer, who is able to pick his fighting strategy based on the
And here is the mighty dragonslayer, who can pick his fighting strategy based on the
opponent.

```java
Expand All @@ -95,7 +95,7 @@ public class DragonSlayer {
}
```

Finally here's the dragonslayer in action.
Finally, here's the dragonslayer in action.

```java
LOGGER.info("Green dragon spotted ahead!");
Expand All @@ -120,7 +120,7 @@ Program output:
You cast the spell of disintegration and the dragon vaporizes in a pile of dust!
```

What's more, the new feature Lambda Expressions in Java 8 provides another approach for the implementation:
What's more, the lambda expressions in Java 8 provides another approach for the implementation:

```java
public class LambdaStrategy {
Expand Down Expand Up @@ -163,7 +163,7 @@ And here's the dragonslayer in action.
dragonSlayer.goToBattle();
```

Program output is the same as above one.
The program output is the same as the above one.

## Class diagram

Expand All @@ -175,8 +175,8 @@ Use the Strategy pattern when

* Many related classes differ only in their behavior. Strategies provide a way to configure a class either one of many behaviors
* 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
* An algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures
* 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
* An algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex algorithm-specific data structures
* 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

## Tutorial

Expand Down
2 changes: 1 addition & 1 deletion strategy/src/main/java/com/iluwatar/strategy/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* enables an algorithm's behavior to be selected at runtime.</p>
*
* <p>Before Java 8 the Strategies needed to be separate classes forcing the developer
* to write lots of boilerplate code. With modern Java it is easy to pass behavior
* to write lots of boilerplate code. With modern Java, it is easy to pass behavior
* with method references and lambdas making the code shorter and more readable.</p>
*
* <p>In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing
Expand Down