diff --git a/decorator/src/main/java/com/iluwatar/App.java b/decorator/src/main/java/com/iluwatar/App.java index 3ff421ffe..8318091da 100644 --- a/decorator/src/main/java/com/iluwatar/App.java +++ b/decorator/src/main/java/com/iluwatar/App.java @@ -6,18 +6,23 @@ package com.iluwatar; * class implements the same interface as the target and uses composition to * "decorate" calls to the target. * + * Using decorator pattern it is possible to change class behavior during + * runtime, as the example shows. + * */ public class App { public static void main(String[] args) { + // simple troll System.out.println("A simple looking troll approaches."); Hostile troll = new Troll(); troll.attack(); troll.fleeBattle(); + // change the behavior of the simple troll by adding a decorator System.out.println("\nA smart looking troll surprises you."); - Hostile smart = new SmartTroll(new Troll()); + Hostile smart = new SmartTroll(troll); smart.attack(); smart.fleeBattle(); }