diff --git a/strategy/README.md b/strategy/README.md index 21ac1c94b..b2330ceb8 100644 --- a/strategy/README.md +++ b/strategy/README.md @@ -9,17 +9,20 @@ tags: --- ## Also known as + 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. + +Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets +the algorithm vary independently from clients that use it. ## Explanation Real world example -> Slaying dragons is a dangerous profession. With experience it becomes easier. Veteran dragonslayers have developed different fighting strategies against different types of dragons. +> 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 @@ -27,7 +30,8 @@ In plain words Wikipedia says -> In computer programming, the strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting an algorithm at runtime. +> In computer programming, the strategy pattern (also known as the policy pattern) is a behavioral +> software design pattern that enables selecting an algorithm at runtime. **Programmatic Example** @@ -71,7 +75,8 @@ public class SpellStrategy implements DragonSlayingStrategy { } ``` -And here is the mighty dragonslayer who is able to pick his fighting strategy based on the opponent. +And here is the mighty dragonslayer, who is able to pick his fighting strategy based on the +opponent. ```java public class DragonSlayer { @@ -92,7 +97,7 @@ public class DragonSlayer { } ``` -Finally here's dragonslayer in action. +Finally here's the dragonslayer in action. ```java LOGGER.info("Green dragon spotted ahead!"); @@ -104,19 +109,25 @@ Finally here's dragonslayer in action. LOGGER.info("Black dragon lands before you."); dragonSlayer.changeStrategy(new SpellStrategy()); dragonSlayer.goToBattle(); - - // Green dragon spotted ahead! - // With your Excalibur you sever the dragon's head! - // Red dragon emerges. - // You shoot the dragon with the magical crossbow and it falls dead on the ground! - // Black dragon lands before you. - // You cast the spell of disintegration and the dragon vaporizes in a pile of dust! +``` + +Program output: + +``` + Green dragon spotted ahead! + With your Excalibur you sever the dragon's head! + Red dragon emerges. + You shoot the dragon with the magical crossbow and it falls dead on the ground! + Black dragon lands before you. + You cast the spell of disintegration and the dragon vaporizes in a pile of dust! ``` ## Class diagram -![alt text](./etc/strategy_1.png "Strategy") + +![alt text](./etc/strategy_urm.png "Strategy") ## Applicability + 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 diff --git a/strategy/etc/strategy.png b/strategy/etc/strategy.png deleted file mode 100644 index ae7442150..000000000 Binary files a/strategy/etc/strategy.png and /dev/null differ diff --git a/strategy/etc/strategy.ucls b/strategy/etc/strategy.ucls deleted file mode 100644 index 9eba02417..000000000 --- a/strategy/etc/strategy.ucls +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/strategy/etc/strategy_1.png b/strategy/etc/strategy_1.png deleted file mode 100644 index c341e58c6..000000000 Binary files a/strategy/etc/strategy_1.png and /dev/null differ diff --git a/strategy/etc/strategy_urm.png b/strategy/etc/strategy_urm.png new file mode 100644 index 000000000..8e15c3c36 Binary files /dev/null and b/strategy/etc/strategy_urm.png differ