Skip to content

Commit

Permalink
decorator 패턴
Browse files Browse the repository at this point in the history
  • Loading branch information
ZANGZANGS committed Dec 16, 2021
1 parent 527023d commit a3a97ba
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gof/dp/decorator/Coffee.java
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();
}
23 changes: 23 additions & 0 deletions src/gof/dp/decorator/CoffeeTest.java
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();

}
}
15 changes: 15 additions & 0 deletions src/gof/dp/decorator/Decorator.java
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();
}

}
10 changes: 10 additions & 0 deletions src/gof/dp/decorator/EtiopiaAmericano.java
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");
}
}

10 changes: 10 additions & 0 deletions src/gof/dp/decorator/KenyaAmericano.java
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");
}
}

12 changes: 12 additions & 0 deletions src/gof/dp/decorator/Latte.java
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");
}
}
12 changes: 12 additions & 0 deletions src/gof/dp/decorator/Mocha.java
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");
}
}
12 changes: 12 additions & 0 deletions src/gof/dp/decorator/WhippedCream.java
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");
}
}

0 comments on commit a3a97ba

Please sign in to comment.