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
5 changed files
with
98 additions
and
1 deletion.
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,12 @@ | ||
package template.examples.ordermanaging; | ||
|
||
public class Client { | ||
|
||
public static void main(String[] args) { | ||
OrderProcessTemplate netOrder = new NetOrder(); | ||
netOrder.processOrder(true); | ||
System.out.println(); | ||
OrderProcessTemplate storeOrder = new StoreOrder(); | ||
storeOrder.processOrder(true); | ||
} | ||
} |
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,21 @@ | ||
package template.examples.ordermanaging; | ||
|
||
public class NetOrder extends OrderProcessTemplate { | ||
@Override | ||
public void doSelect() { | ||
System.out.println("Item added to online shopping cart"); | ||
System.out.println("Get gift wrap preference"); | ||
System.out.println("Get delivery address."); | ||
} | ||
|
||
@Override | ||
public void doPayment() { | ||
System.out.println("Online Payment through Netbanking, card or Paytm"); | ||
} | ||
|
||
@Override | ||
public void doDelivery() { | ||
System.out.println("Ship the item through post to delivery address"); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/template/examples/ordermanaging/OrderProcessTemplate.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,29 @@ | ||
package template.examples.ordermanaging; | ||
|
||
public abstract class OrderProcessTemplate { | ||
public boolean isGift; | ||
|
||
public abstract void doSelect(); | ||
|
||
public abstract void doPayment(); | ||
|
||
public abstract void doDelivery(); | ||
|
||
public final void processOrder(boolean isGift) { | ||
doSelect(); | ||
doPayment(); | ||
if (isGift) { | ||
giftWrap(); | ||
} | ||
doDelivery(); | ||
} | ||
|
||
public final void giftWrap() { | ||
try { | ||
System.out.println("Gift wrap successfull"); | ||
} | ||
catch (Exception e) { | ||
System.out.println("Gift wrap unsuccessful"); | ||
} | ||
} | ||
} |
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,19 @@ | ||
package template.examples.ordermanaging; | ||
|
||
public class StoreOrder extends OrderProcessTemplate { | ||
|
||
@Override | ||
public void doSelect() { | ||
System.out.println("Customer chooses the item from shelf."); | ||
} | ||
|
||
@Override | ||
public void doPayment() { | ||
System.out.println("Pays at counter through cash/POS"); | ||
} | ||
|
||
@Override | ||
public void doDelivery() { | ||
System.out.println("Item deliverd to in delivery counter."); | ||
} | ||
} |