-
Notifications
You must be signed in to change notification settings - Fork 1
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
8 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package gof.dp.decorator; | ||
|
||
public abstract class Coffee { | ||
|
||
public abstract void brewing(); | ||
} |
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 gof.dp.decorator; | ||
|
||
public class CoffeeTest { | ||
public static void main(String[] args) { | ||
Coffee etiopiaAmericano = new EtiopiaAmericano(); | ||
etiopiaAmericano.brewing(); | ||
System.out.println(); | ||
|
||
Coffee kenyaLatte = new Latte(new KenyaAmericano()); | ||
kenyaLatte.brewing(); | ||
System.out.println(); | ||
|
||
Mocha kenyaMocha = new Mocha(new Latte(new KenyaAmericano())); | ||
kenyaMocha.brewing(); | ||
System.out.println(); | ||
|
||
WhippedCream etiopiaWhippedMocha = | ||
new WhippedCream(new Mocha(new Latte( new EtiopiaAmericano()))); | ||
etiopiaWhippedMocha.brewing(); | ||
System.out.println(); | ||
|
||
} | ||
} |
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,15 @@ | ||
package gof.dp.decorator; | ||
|
||
public abstract class Decorator extends Coffee{ | ||
|
||
Coffee coffee; | ||
public Decorator(Coffee coffee){ | ||
this.coffee = coffee; | ||
} | ||
|
||
@Override | ||
public void brewing(){ | ||
coffee.brewing(); | ||
} | ||
|
||
} |
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 gof.dp.decorator; | ||
|
||
public class EtiopiaAmericano extends Coffee{ | ||
|
||
@Override | ||
public void brewing() { | ||
System.out.println("EtiopiaAmericano"); | ||
} | ||
} | ||
|
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 gof.dp.decorator; | ||
|
||
public class KenyaAmericano extends Coffee{ | ||
|
||
@Override | ||
public void brewing() { | ||
System.out.println("KenyaAmericano"); | ||
} | ||
} | ||
|
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 gof.dp.decorator; | ||
|
||
public class Latte extends Decorator{ | ||
public Latte(Coffee coffee) { | ||
super(coffee); | ||
} | ||
|
||
public void brewing(){ | ||
super.brewing(); | ||
System.out.println("Add Milk"); | ||
} | ||
} |
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 gof.dp.decorator; | ||
|
||
public class Mocha extends Decorator{ | ||
public Mocha(Coffee coffee) { | ||
super(coffee); | ||
} | ||
|
||
public void brewing(){ | ||
super.brewing(); | ||
System.out.println("Add Mocha"); | ||
} | ||
} |
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 gof.dp.decorator; | ||
|
||
public class WhippedCream extends Decorator{ | ||
public WhippedCream(Coffee coffee) { | ||
super(coffee); | ||
} | ||
|
||
public void brewing(){ | ||
super.brewing(); | ||
System.out.println("Add WhippedCream"); | ||
} | ||
} |