-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Diner example for Command Pattern to show non-Lambda version,…
… and add separate Lambda version
- Loading branch information
1 parent
5da3229
commit 1eaf6bb
Showing
7 changed files
with
66 additions
and
5 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
14 changes: 14 additions & 0 deletions
14
src/headfirst/designpatterns/command/dinerLambda/Cook.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,14 @@ | ||
package headfirst.designpatterns.command.dinerLambda; | ||
|
||
public class Cook { | ||
|
||
public Cook() {} | ||
|
||
public void makeBurger() { | ||
System.out.println("Making a burger"); | ||
} | ||
|
||
public void makeFries() { | ||
System.out.println("Making fries"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/headfirst/designpatterns/command/dinerLambda/Customer.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,17 @@ | ||
package headfirst.designpatterns.command.dinerLambda; | ||
|
||
public class Customer { | ||
Waitress waitress; | ||
Cook cook; | ||
Order o; | ||
public Customer(Waitress waitress, Cook cook) { | ||
this.waitress = waitress; | ||
this.cook = cook; | ||
} | ||
public void createOrder() { | ||
Order o = () -> { cook.makeBurger(); cook.makeFries(); }; | ||
} | ||
public void hungry() { | ||
waitress.takeOrder(o); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/headfirst/designpatterns/command/dinerLambda/Diner.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,11 @@ | ||
package headfirst.designpatterns.command.dinerLambda; | ||
|
||
public class Diner { | ||
public static void main(String[] args) { | ||
Cook cook = new Cook(); | ||
Waitress waitress = new Waitress(); | ||
Customer customer = new Customer(waitress, cook); | ||
customer.createOrder(); | ||
customer.hungry(); | ||
} | ||
} |
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,6 @@ | ||
package headfirst.designpatterns.command.dinerLambda; | ||
|
||
@FunctionalInterface | ||
public interface Order { | ||
public void orderUp(); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/headfirst/designpatterns/command/dinerLambda/Waitress.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,10 @@ | ||
package headfirst.designpatterns.command.dinerLambda; | ||
|
||
public class Waitress { | ||
Order order; | ||
public Waitress() {} | ||
public void takeOrder(Order order) { | ||
this.order = order; | ||
order.orderUp(); | ||
} | ||
} |