File tree Expand file tree Collapse file tree 5 files changed +78
-0
lines changed
src/main/java/com/iluwatar Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <project xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" >
4+ <modelVersion >4.0.0</modelVersion >
5+ <parent >
6+ <groupId >com.iluwatar</groupId >
7+ <artifactId >java-design-patterns</artifactId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <groupId >com.iluwatar</groupId >
11+ <artifactId >decorator</artifactId >
12+ <version >1.0-SNAPSHOT</version >
13+ <name >decorator</name >
14+ <url >http://maven.apache.org</url >
15+ <dependencies >
16+ <dependency >
17+ <groupId >junit</groupId >
18+ <artifactId >junit</artifactId >
19+ <version >3.8.1</version >
20+ <scope >test</scope >
21+ </dependency >
22+ </dependencies >
23+ </project >
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class App
4+ {
5+ public static void main ( String [] args )
6+ {
7+
8+ System .out .println ("A simple looking troll approaches." );
9+ Troll troll = new Troll ();
10+ troll .attack ();
11+ troll .fleeBattle ();
12+
13+ System .out .println ("\n A smart looking troll surprises you." );
14+ Troll smart = new SmartTroll (new Troll ());
15+ smart .attack ();
16+ smart .fleeBattle ();
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class SmartTroll extends Troll {
4+
5+ private Troll decorated ;
6+
7+ public SmartTroll (Troll decorated ) {
8+ this .decorated = decorated ;
9+ }
10+
11+ @ Override
12+ public void attack () {
13+ System .out .println ("The troll throws a rock at you!" );
14+ decorated .attack ();
15+ }
16+
17+ @ Override
18+ public void fleeBattle () {
19+ System .out .println ("The troll calls for help!" );
20+ decorated .fleeBattle ();
21+ }
22+
23+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class Troll {
4+
5+ public void attack () {
6+ System .out .println ("The troll swings at you with a club!" );
7+ }
8+
9+ public void fleeBattle () {
10+ System .out .println ("The troll shrieks in horror and runs away!" );
11+ }
12+
13+ }
Original file line number Diff line number Diff line change 2626 <module >adapter</module >
2727 <module >bridge</module >
2828 <module >composite</module >
29+ <module >decorator</module >
2930 </modules >
3031</project >
You can’t perform that action at this time.
0 commit comments