Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit22ddd57

Browse files
authored
sonar fix: Update App.java (iluwatar#1898)
1 parent72bb189 commit22ddd57

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
publicclassApp {
4343

44+
privatestaticfinalStringRED_DRAGON_EMERGES ="Red dragon emerges.";
45+
privatestaticfinalStringGREEN_DRAGON_SPOTTED ="Green dragon spotted ahead!";
46+
privatestaticfinalStringBLACK_DRAGON_LANDS ="Black dragon lands before you.";
47+
4448
/**
4549
* Program entry point.
4650
*
4751
* @param args command line args
4852
*/
4953
publicstaticvoidmain(String[]args) {
5054
// GoF Strategy pattern
51-
LOGGER.info("Green dragon spotted ahead!");
55+
LOGGER.info(GREEN_DRAGON_SPOTTED);
5256
vardragonSlayer =newDragonSlayer(newMeleeStrategy());
5357
dragonSlayer.goToBattle();
54-
LOGGER.info("Red dragon emerges.");
58+
LOGGER.info(RED_DRAGON_EMERGES);
5559
dragonSlayer.changeStrategy(newProjectileStrategy());
5660
dragonSlayer.goToBattle();
57-
LOGGER.info("Black dragon lands before you.");
61+
LOGGER.info(BLACK_DRAGON_LANDS);
5862
dragonSlayer.changeStrategy(newSpellStrategy());
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 =newDragonSlayer(
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)

[8]ページ先頭

©2009-2025 Movatter.jp