File tree Expand file tree Collapse file tree 8 files changed +160
-1
lines changed
src/main/java/com/iluwatar Expand file tree Collapse file tree 8 files changed +160
-1
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 >facade</artifactId >
12+ <version >1.0-SNAPSHOT</version >
13+ <name >facade</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+ DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade ();
8+ facade .startNewDay ();
9+ facade .digOutGold ();
10+ facade .endDay ();
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class DwarvenCartOperator extends DwarvenMineWorker {
4+
5+ @ Override
6+ public void work () {
7+ System .out .println (name () + " moves gold chunks out of the mine." );
8+ }
9+
10+ @ Override
11+ public String name () {
12+ return "Dwarf cart operator" ;
13+ }
14+
15+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class DwarvenGoldDigger extends DwarvenMineWorker {
4+
5+ @ Override
6+ public void work () {
7+ System .out .println (name () + " digs for gold." );
8+ }
9+
10+ @ Override
11+ public String name () {
12+ return "Dwarf gold digger" ;
13+ }
14+
15+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
6+ public class DwarvenGoldmineFacade {
7+
8+ List <DwarvenMineWorker > workers ;
9+
10+ public DwarvenGoldmineFacade () {
11+ workers = new ArrayList <>();
12+ workers .add (new DwarvenGoldDigger ());
13+ workers .add (new DwarvenCartOperator ());
14+ workers .add (new DwarvenTunnelDigger ());
15+ }
16+
17+ public void startNewDay () {
18+ for (DwarvenMineWorker worker : workers ) {
19+ worker .wakeUp ();
20+ worker .goToMine ();
21+ }
22+ }
23+
24+ public void digOutGold () {
25+ for (DwarvenMineWorker worker : workers ) {
26+ worker .work ();
27+ }
28+ }
29+
30+ public void endDay () {
31+ for (DwarvenMineWorker worker : workers ) {
32+ worker .goHome ();
33+ worker .goToSleep ();
34+ }
35+ }
36+
37+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public abstract class DwarvenMineWorker {
4+
5+ public void goToSleep () {
6+ System .out .println (name () + " goes to sleep." );
7+ }
8+
9+ public void wakeUp () {
10+ System .out .println (name () + " wakes up." );
11+ }
12+
13+ public void goHome () {
14+ System .out .println (name () + " goes home." );
15+ }
16+
17+ public void goToMine () {
18+ System .out .println (name () + " goes to the mine." );
19+ }
20+
21+ public abstract void work ();
22+
23+ public abstract String name ();
24+
25+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class DwarvenTunnelDigger extends DwarvenMineWorker {
4+
5+ @ Override
6+ public void work () {
7+ System .out .println (name () + " creates another promising tunnel." );
8+ }
9+
10+ @ Override
11+ public String name () {
12+ return "Dwarven tunnel digger" ;
13+ }
14+
15+ }
Original file line number Diff line number Diff line change 2727 <module >bridge</module >
2828 <module >composite</module >
2929 <module >decorator</module >
30+ <module >facade</module >
3031 </modules >
31- </project >
32+
33+ <build >
34+ <plugins >
35+ <!-- Tell maven to compile using Java 1.7 -->
36+ <plugin >
37+ <groupId >org.apache.maven.plugins</groupId >
38+ <artifactId >maven-compiler-plugin</artifactId >
39+ <version >3.0</version >
40+ <configuration >
41+ <source >1.7</source >
42+ <target >1.7</target >
43+ </configuration >
44+ </plugin >
45+ </plugins >
46+ </build >
47+
48+ </project >
You can’t perform that action at this time.
0 commit comments