#502 Replaced usages of System.out with logger.
This commit is contained in:
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.decorator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Decorator pattern is a more flexible alternative to subclassing. The Decorator class
|
||||
@ -36,6 +39,8 @@ package com.iluwatar.decorator;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
@ -44,17 +49,17 @@ public class App {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// simple troll
|
||||
System.out.println("A simple looking troll approaches.");
|
||||
LOGGER.info("A simple looking troll approaches.");
|
||||
Hostile troll = new Troll();
|
||||
troll.attack();
|
||||
troll.fleeBattle();
|
||||
System.out.printf("Simple troll power %d.\n", troll.getAttackPower());
|
||||
LOGGER.info("Simple troll power {}.\n", troll.getAttackPower());
|
||||
|
||||
// change the behavior of the simple troll by adding a decorator
|
||||
System.out.println("\nA smart looking troll surprises you.");
|
||||
LOGGER.info("A smart looking troll surprises you.");
|
||||
Hostile smart = new SmartHostile(troll);
|
||||
smart.attack();
|
||||
smart.fleeBattle();
|
||||
System.out.printf("Smart troll power %d.\n", smart.getAttackPower());
|
||||
LOGGER.info("Smart troll power {}.\n", smart.getAttackPower());
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.decorator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* SmartHostile is a decorator for {@link Hostile} objects. The calls to the {@link Hostile} interface
|
||||
* are intercepted and decorated. Finally the calls are delegated to the decorated {@link Hostile}
|
||||
@ -30,6 +33,8 @@ package com.iluwatar.decorator;
|
||||
*/
|
||||
public class SmartHostile implements Hostile {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SmartHostile.class);
|
||||
|
||||
private Hostile decorated;
|
||||
|
||||
public SmartHostile(Hostile decorated) {
|
||||
@ -38,7 +43,7 @@ public class SmartHostile implements Hostile {
|
||||
|
||||
@Override
|
||||
public void attack() {
|
||||
System.out.println("It throws a rock at you!");
|
||||
LOGGER.info("It throws a rock at you!");
|
||||
decorated.attack();
|
||||
}
|
||||
|
||||
@ -50,7 +55,7 @@ public class SmartHostile implements Hostile {
|
||||
|
||||
@Override
|
||||
public void fleeBattle() {
|
||||
System.out.println("It calls for help!");
|
||||
LOGGER.info("It calls for help!");
|
||||
decorated.fleeBattle();
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.decorator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Troll implements {@link Hostile} interface directly.
|
||||
@ -29,9 +32,11 @@ package com.iluwatar.decorator;
|
||||
*/
|
||||
public class Troll implements Hostile {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Troll.class);
|
||||
|
||||
@Override
|
||||
public void attack() {
|
||||
System.out.println("The troll swings at you with a club!");
|
||||
LOGGER.info("The troll swings at you with a club!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,6 +46,6 @@ public class Troll implements Hostile {
|
||||
|
||||
@Override
|
||||
public void fleeBattle() {
|
||||
System.out.println("The troll shrieks in horror and runs away!");
|
||||
LOGGER.info("The troll shrieks in horror and runs away!");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user