Skip to content

Commit 22ddd57

Browse files
authored
sonar fix: Update App.java (iluwatar#1898)
1 parent 72bb189 commit 22ddd57

File tree

1 file changed

+13
-9
lines changed
  • strategy/src/main/java/com/iluwatar/strategy

1 file changed

+13
-9
lines changed

strategy/src/main/java/com/iluwatar/strategy/App.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,45 +41,49 @@
4141
@Slf4j
4242
public class App {
4343

44+
private static final String RED_DRAGON_EMERGES = "Red dragon emerges.";
45+
private static final String GREEN_DRAGON_SPOTTED = "Green dragon spotted ahead!";
46+
private static final String BLACK_DRAGON_LANDS = "Black dragon lands before you.";
47+
4448
/**
4549
* Program entry point.
4650
*
4751
* @param args command line args
4852
*/
4953
public static void main(String[] args) {
5054
// GoF Strategy pattern
51-
LOGGER.info("Green dragon spotted ahead!");
55+
LOGGER.info(GREEN_DRAGON_SPOTTED);
5256
var dragonSlayer = new DragonSlayer(new MeleeStrategy());
5357
dragonSlayer.goToBattle();
54-
LOGGER.info("Red dragon emerges.");
58+
LOGGER.info(RED_DRAGON_EMERGES);
5559
dragonSlayer.changeStrategy(new ProjectileStrategy());
5660
dragonSlayer.goToBattle();
57-
LOGGER.info("Black dragon lands before you.");
61+
LOGGER.info(BLACK_DRAGON_LANDS);
5862
dragonSlayer.changeStrategy(new SpellStrategy());
5963
dragonSlayer.goToBattle();
6064

6165
// Java 8 functional implementation Strategy pattern
62-
LOGGER.info("Green dragon spotted ahead!");
66+
LOGGER.info(GREEN_DRAGON_SPOTTED);
6367
dragonSlayer = new DragonSlayer(
6468
() -> LOGGER.info("With your Excalibur you severe the dragon's head!"));
6569
dragonSlayer.goToBattle();
66-
LOGGER.info("Red dragon emerges.");
70+
LOGGER.info(RED_DRAGON_EMERGES);
6771
dragonSlayer.changeStrategy(() -> LOGGER.info(
6872
"You shoot the dragon with the magical crossbow and it falls dead on the ground!"));
6973
dragonSlayer.goToBattle();
70-
LOGGER.info("Black dragon lands before you.");
74+
LOGGER.info(BLACK_DRAGON_LANDS);
7175
dragonSlayer.changeStrategy(() -> LOGGER.info(
7276
"You cast the spell of disintegration and the dragon vaporizes in a pile of dust!"));
7377
dragonSlayer.goToBattle();
7478

7579
// Java 8 lambda implementation with enum Strategy pattern
76-
LOGGER.info("Green dragon spotted ahead!");
80+
LOGGER.info(GREEN_DRAGON_SPOTTED);
7781
dragonSlayer.changeStrategy(LambdaStrategy.Strategy.MeleeStrategy);
7882
dragonSlayer.goToBattle();
79-
LOGGER.info("Red dragon emerges.");
83+
LOGGER.info(RED_DRAGON_EMERGES);
8084
dragonSlayer.changeStrategy(LambdaStrategy.Strategy.ProjectileStrategy);
8185
dragonSlayer.goToBattle();
82-
LOGGER.info("Black dragon lands before you.");
86+
LOGGER.info(BLACK_DRAGON_LANDS);
8387
dragonSlayer.changeStrategy(LambdaStrategy.Strategy.SpellStrategy);
8488
dragonSlayer.goToBattle();
8589
}

0 commit comments

Comments
 (0)