File tree Expand file tree Collapse file tree
decorator/src/main/java/com/iluwatar Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 */
1013public 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 ("\n A 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 }
You can’t perform that action at this time.
0 commit comments