diff --git a/.all-contributorsrc b/.all-contributorsrc index d19c152f9..13876cc83 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1712,6 +1712,15 @@ "contributions": [ "doc" ] + }, + { + "login": "harshalkh", + "name": "Harshal", + "avatar_url": "https://avatars.githubusercontent.com/u/37841724?v=4", + "profile": "https://github.com/harshalkh", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index 52303f5d4..2a7e43185 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns) [![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![All Contributors](https://img.shields.io/badge/all_contributors-188-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-189-orange.svg?style=flat-square)](#contributors-)
@@ -316,6 +316,7 @@ This project is licensed under the terms of the MIT license.
Anum Amin

📖
Reo Uehara

🌍
Fiordy

📖 +
Harshal

💻 diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/App.java b/factory-method/src/main/java/com/iluwatar/factory/method/App.java index b76a918d1..d903ee7c7 100644 --- a/factory-method/src/main/java/com/iluwatar/factory/method/App.java +++ b/factory-method/src/main/java/com/iluwatar/factory/method/App.java @@ -41,6 +41,8 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class App { + private static final String MANUFACTURED = "{} manufactured {}"; + /** * Program entry point. * @param args command line args @@ -49,14 +51,14 @@ public class App { Blacksmith blacksmith = new OrcBlacksmith(); Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR); - LOGGER.info("{} manufactured {}", blacksmith, weapon); + LOGGER.info(MANUFACTURED, blacksmith, weapon); weapon = blacksmith.manufactureWeapon(WeaponType.AXE); - LOGGER.info("{} manufactured {}", blacksmith, weapon); + LOGGER.info(MANUFACTURED, blacksmith, weapon); blacksmith = new ElfBlacksmith(); weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR); - LOGGER.info("{} manufactured {}", blacksmith, weapon); + LOGGER.info(MANUFACTURED, blacksmith, weapon); weapon = blacksmith.manufactureWeapon(WeaponType.AXE); - LOGGER.info("{} manufactured {}", blacksmith, weapon); + LOGGER.info(MANUFACTURED, blacksmith, weapon); } } diff --git a/strategy/src/main/java/com/iluwatar/strategy/App.java b/strategy/src/main/java/com/iluwatar/strategy/App.java index 383712c39..d54c06008 100644 --- a/strategy/src/main/java/com/iluwatar/strategy/App.java +++ b/strategy/src/main/java/com/iluwatar/strategy/App.java @@ -41,6 +41,10 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class App { + private static final String RED_DRAGON_EMERGES = "Red dragon emerges."; + private static final String GREEN_DRAGON_SPOTTED = "Green dragon spotted ahead!"; + private static final String BLACK_DRAGON_LANDS = "Black dragon lands before you."; + /** * Program entry point. * @@ -48,38 +52,38 @@ public class App { */ public static void main(String[] args) { // GoF Strategy pattern - LOGGER.info("Green dragon spotted ahead!"); + LOGGER.info(GREEN_DRAGON_SPOTTED); var dragonSlayer = new DragonSlayer(new MeleeStrategy()); dragonSlayer.goToBattle(); - LOGGER.info("Red dragon emerges."); + LOGGER.info(RED_DRAGON_EMERGES); dragonSlayer.changeStrategy(new ProjectileStrategy()); dragonSlayer.goToBattle(); - LOGGER.info("Black dragon lands before you."); + LOGGER.info(BLACK_DRAGON_LANDS); dragonSlayer.changeStrategy(new SpellStrategy()); dragonSlayer.goToBattle(); // Java 8 functional implementation Strategy pattern - LOGGER.info("Green dragon spotted ahead!"); + LOGGER.info(GREEN_DRAGON_SPOTTED); dragonSlayer = new DragonSlayer( () -> LOGGER.info("With your Excalibur you severe the dragon's head!")); dragonSlayer.goToBattle(); - LOGGER.info("Red dragon emerges."); + LOGGER.info(RED_DRAGON_EMERGES); dragonSlayer.changeStrategy(() -> LOGGER.info( "You shoot the dragon with the magical crossbow and it falls dead on the ground!")); dragonSlayer.goToBattle(); - LOGGER.info("Black dragon lands before you."); + LOGGER.info(BLACK_DRAGON_LANDS); dragonSlayer.changeStrategy(() -> LOGGER.info( "You cast the spell of disintegration and the dragon vaporizes in a pile of dust!")); dragonSlayer.goToBattle(); // Java 8 lambda implementation with enum Strategy pattern - LOGGER.info("Green dragon spotted ahead!"); + LOGGER.info(GREEN_DRAGON_SPOTTED); dragonSlayer.changeStrategy(LambdaStrategy.Strategy.MeleeStrategy); dragonSlayer.goToBattle(); - LOGGER.info("Red dragon emerges."); + LOGGER.info(RED_DRAGON_EMERGES); dragonSlayer.changeStrategy(LambdaStrategy.Strategy.ProjectileStrategy); dragonSlayer.goToBattle(); - LOGGER.info("Black dragon lands before you."); + LOGGER.info(BLACK_DRAGON_LANDS); dragonSlayer.changeStrategy(LambdaStrategy.Strategy.SpellStrategy); dragonSlayer.goToBattle(); }