Merged
Conversation
guswns3371
commented
Nov 20, 2022
Comment on lines
+5
to
+21
| public abstract class PizzaStore { | ||
|
|
||
| public Pizza orderPizza(Pizza.PizzaType pizzaType) { | ||
| final Pizza pizza = createPizza(pizzaType); | ||
|
|
||
| pizza.prepare(); | ||
| pizza.bake(); | ||
| pizza.cut(); | ||
| pizza.box(); | ||
|
|
||
| return pizza; | ||
| } | ||
|
|
||
| // pizza 인스턴스를 만드는 작업은 팩토리 메소드에서 처리하도록 함. | ||
| // 구상 클래스마다 서로 다른 피자를 만들기 위해 abstract으로 선언 | ||
| protected abstract Pizza createPizza(Pizza.PizzaType pizzaType); | ||
| } |
Member
Author
There was a problem hiding this comment.
PizzaStore의 createPizza() 를 구현하는 방식은 2가지가 있다
- 서로 다른 팩토리를 만들고, PizzaStore에서 적당한 팩토리를 사용하는 방법
createPizza()메소드를 추상 메소드로 선언하고, PizzaStore의 서브 클래스를 구현하는 방법
1번 방식
피자 가게와 피자 만드는 과정을 하나로 묶지 못한다. (유연성이 낮음)
2번 방식
PizzaStore nyStore = new NYPizzaStore();
PizzaStore chicagoStore = new ChicagoPizzaStore();
Pizza pizza = nyStore.orderPizza(CHEESE); // 뉴욕 피자 스타일의 치즈 피자
pizza = chicagoStore(CHEESE); // 시카고 피자 스타일의 치즈 피자
Comment on lines
+10
to
+25
| public class ChicagoPizzaStore extends PizzaStore { | ||
|
|
||
| @Override | ||
| protected Pizza createPizza(Pizza.PizzaType pizzaType) { | ||
| Pizza pizza = null; | ||
| PizzaIngredientFactory pizzaIngredientFactory = new ChicagoPizzaIngredientFactory(); | ||
| if (Pizza.PizzaType.CHEESE.equals(pizzaType)) { | ||
| pizza = new ChicagoStyleCheesePizza(pizzaIngredientFactory); | ||
| pizza.setName("시카고 스타일 치즈 피자"); | ||
| } else if (Pizza.PizzaType.PEPPERONI.equals(pizzaType)) { | ||
| pizza = new ChicagoStylePepperoniPizza(pizzaIngredientFactory); | ||
| pizza.setName("시카고 스타일 페퍼로니 피자"); | ||
| } | ||
| return pizza; | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
createPizza() 를 피자집 스타일에 맞게 생성한다.
PizzaStore
- 추상 생산자(abstract creator) 클래스 PizzaStore는 팩토리 메소드(추상 메소드 = createPizza)를 정의한다
구상 PizzaStore
- ChicagoPizzaStore 와 같은 구상 생산자(concrete creator)는 추상 생산자의 팩토리 메소드를 구현한다
Comment on lines
+5
to
+14
| public abstract class Pizza { | ||
| protected String name; | ||
| protected Dough dough; | ||
| protected Sauce sauce; | ||
| protected Veggies[] veggies; | ||
| protected Cheese cheese; | ||
| protected Pepperoni pepperoni; | ||
| protected Clams clam; | ||
|
|
||
| public abstract void prepare(); |
Member
Author
Comment on lines
+8
to
+15
| public interface PizzaIngredientFactory { | ||
| Dough createDough(); | ||
| Sauce createSauce(); | ||
| Cheese createCheese(); | ||
| Veggies[] createVeggies(); | ||
| Pepperoni createPepperoni(); | ||
| Clams createClam(); | ||
| } |
Member
Author
There was a problem hiding this comment.
의존성 뒤집기 원칙(Dependency Inversion Priciple)을 활용하여
PizzaStore(고수준 구성 요소)가 가지는 피자 객체(저수준 구성 요소)에 대한 의존성을 없애기 위해
추상 팩토리 패턴 을 활용한다.
각 PizzStore 구상 클래스는 PizzaIngredientFactory를 통해 생성된 원재료를 세팅해주면 된다.
(PizzaIngredientFactory 또한 피자집의 성격에 맞는 구상 클래스를 구현해야한다.)
추상 팩토리 패턴
구상 클래스에 의존하지 않고도 서로 연관되거나 의존적인 객체로 이루어진 제품군을 생산하는 인터페이스를 제공합니다. 구상 클래스는 서브클래스에서 만듭니다
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




No description provided.