Skip to content

Commit 9336284

Browse files
committed
Improved decorator example.
1 parent 10d4e3c commit 9336284

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • decorator/src/main/java/com/iluwatar

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
* class implements the same interface as the target and uses composition to
77
* "decorate" calls to the target.
88
*
9+
* Using decorator pattern it is possible to change class behavior during
10+
* runtime, as the example shows.
11+
*
912
*/
1013
public class App {
1114

1215
public static void main(String[] args) {
1316

17+
// simple troll
1418
System.out.println("A simple looking troll approaches.");
1519
Hostile troll = new Troll();
1620
troll.attack();
1721
troll.fleeBattle();
1822

23+
// change the behavior of the simple troll by adding a decorator
1924
System.out.println("\nA smart looking troll surprises you.");
20-
Hostile smart = new SmartTroll(new Troll());
25+
Hostile smart = new SmartTroll(troll);
2126
smart.attack();
2227
smart.fleeBattle();
2328
}

0 commit comments

Comments
 (0)