forked from luisburgos/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mediator.examples.airtrafficcontroller; | ||
|
||
public class Client { | ||
|
||
public static void main(String args[]) { | ||
|
||
ControlTower mediator = new ControlTower(); | ||
|
||
Flight sparrow101 = new Flight(mediator); | ||
Runway mainRunway = new Runway(mediator); | ||
|
||
mediator.registerFlight(sparrow101); | ||
mediator.registerRunway(mainRunway); | ||
|
||
sparrow101.getReady(); | ||
|
||
mainRunway.land(); | ||
sparrow101.land(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package mediator.examples.airtrafficcontroller; | ||
|
||
interface Command{ | ||
void land(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/mediator/examples/airtrafficcontroller/ControlTower.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mediator.examples.airtrafficcontroller; | ||
|
||
public class ControlTower { | ||
private Flight flight; | ||
private Runway runway; | ||
public boolean land; | ||
|
||
public void registerRunway(Runway runway) { | ||
this.runway = runway; | ||
} | ||
|
||
public void registerFlight(Flight flight) { | ||
this.flight = flight; | ||
} | ||
|
||
public boolean isLandingOk() { | ||
return land; | ||
} | ||
|
||
public void setLandingStatus(boolean status) { | ||
land = status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mediator.examples.airtrafficcontroller; | ||
|
||
public class Flight implements Command { | ||
private ControlTower mediator; | ||
|
||
public Flight(ControlTower mediator) { | ||
this.mediator = mediator; | ||
} | ||
|
||
public void land() { | ||
if (mediator.isLandingOk()) { | ||
System.out.println("Successfully Landed."); | ||
mediator.setLandingStatus(true); | ||
|
||
} else { | ||
System.out.println("Waiting for landing."); | ||
} | ||
} | ||
|
||
public void getReady() { | ||
System.out.println("Ready for landing."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package mediator.examples.airtrafficcontroller; | ||
|
||
public class Runway implements Command { | ||
private ControlTower mediator; | ||
|
||
public Runway(ControlTower mediator) { | ||
this.mediator = mediator; | ||
mediator.setLandingStatus(false); | ||
} | ||
|
||
@Override | ||
public void land() { | ||
System.out.println("Landing permission granted."); | ||
mediator.setLandingStatus(true); | ||
} | ||
} |