-
Notifications
You must be signed in to change notification settings - Fork 0
4주차: 팩토리패턴 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
4주차: 팩토리패턴 #4
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package factory; | ||
|
|
||
| import factory.pizza.Pizza; | ||
| import factory.pizzastore.impl.ChicagoPizzaStore; | ||
| import factory.pizzastore.impl.NYPizzaStore; | ||
|
|
||
| public class FactoryPattern { | ||
| public static void main(String[] args) { | ||
| final NYPizzaStore nyPizzaStore = new NYPizzaStore(); | ||
| final Pizza pizza = nyPizzaStore.orderPizza(Pizza.PizzaType.CHEESE); | ||
| System.out.println(pizza.toString()); | ||
|
|
||
| final ChicagoPizzaStore chicagoPizzaStore = new ChicagoPizzaStore(); | ||
| final Pizza pizza1 = chicagoPizzaStore.orderPizza(Pizza.PizzaType.PEPPERONI); | ||
| System.out.println(pizza1.toString()); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/factory/ingredient/factory/PizzaIngredientFactory.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package factory.ingredient.factory; | ||
|
|
||
| import factory.ingredient.ingredients.*; | ||
| import factory.ingredient.ingredients.Pepperoni; | ||
| import factory.ingredient.ingredients.Sauce; | ||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public interface PizzaIngredientFactory { | ||
| Dough createDough(); | ||
| Sauce createSauce(); | ||
| Cheese createCheese(); | ||
| Veggies[] createVeggies(); | ||
| Pepperoni createPepperoni(); | ||
| Clams createClam(); | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/factory/ingredient/factory/impl/ChicagoPizzaIngredientFactory.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package factory.ingredient.factory.impl; | ||
|
|
||
| import factory.ingredient.factory.PizzaIngredientFactory; | ||
| import factory.ingredient.ingredients.*; | ||
| import factory.ingredient.ingredients.impl.*; | ||
|
|
||
| public class ChicagoPizzaIngredientFactory implements PizzaIngredientFactory { | ||
|
|
||
| public Dough createDough() { | ||
| return new ThickCrustDough(); | ||
| } | ||
|
|
||
| public Sauce createSauce() { | ||
| return new PlumTomatoSauce(); | ||
| } | ||
|
|
||
| public Cheese createCheese() { | ||
| return new MozzarellaCheese(); | ||
| } | ||
|
|
||
| public Veggies[] createVeggies() { | ||
| return new Veggies[]{ new BlackOlives(), | ||
| new Spinach(), | ||
| new Eggplant() }; | ||
| } | ||
|
|
||
| public Pepperoni createPepperoni() { | ||
| return new SlicedPepperoni(); | ||
| } | ||
|
|
||
| public Clams createClam() { | ||
| return new FrozenClams(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/factory/ingredient/factory/impl/NYPizzaIngredientFactory.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package factory.ingredient.factory.impl; | ||
|
|
||
| import factory.ingredient.factory.PizzaIngredientFactory; | ||
| import factory.ingredient.ingredients.*; | ||
| import factory.ingredient.ingredients.impl.*; | ||
|
|
||
| public class NYPizzaIngredientFactory implements PizzaIngredientFactory { | ||
|
|
||
| public Dough createDough() { | ||
| return new ThinCrustDough(); | ||
| } | ||
|
|
||
| public Sauce createSauce() { | ||
| return new MarinaraSauce(); | ||
| } | ||
|
|
||
| public Cheese createCheese() { | ||
| return new ReggianoCheese(); | ||
| } | ||
|
|
||
| public Veggies[] createVeggies() { | ||
| return new Veggies[]{ new Garlic(), new Onion(), new Mushroom(), new RedPepper() }; | ||
| } | ||
|
|
||
| public Pepperoni createPepperoni() { | ||
| return new SlicedPepperoni(); | ||
| } | ||
|
|
||
| public Clams createClam() { | ||
| return new FreshClams(); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package factory.ingredient.ingredients; | ||
|
|
||
| public interface Cheese { | ||
| public String toString(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package factory.ingredient.ingredients; | ||
|
|
||
| public interface Clams { | ||
| public String toString(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package factory.ingredient.ingredients; | ||
|
|
||
| public interface Dough { | ||
| public String toString(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package factory.ingredient.ingredients; | ||
|
|
||
| public interface Pepperoni { | ||
| public String toString(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package factory.ingredient.ingredients; | ||
|
|
||
| public interface Sauce { | ||
| public String toString(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package factory.ingredient.ingredients; | ||
|
|
||
| public interface Veggies { | ||
| public String toString(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class BlackOlives implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Black Olives"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class Eggplant implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Eggplant"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Clams; | ||
|
|
||
| public class FreshClams implements Clams { | ||
|
|
||
| public String toString() { | ||
| return "Fresh Clams from Long Island Sound"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Clams; | ||
|
|
||
| public class FrozenClams implements Clams { | ||
|
|
||
| public String toString() { | ||
| return "Frozen Clams from Chesapeake Bay"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class Garlic implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Garlic"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Sauce; | ||
|
|
||
| public class MarinaraSauce implements Sauce { | ||
| public String toString() { | ||
| return "Marinara Sauce"; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/factory/ingredient/ingredients/impl/MozzarellaCheese.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Cheese; | ||
|
|
||
| public class MozzarellaCheese implements Cheese { | ||
|
|
||
| public String toString() { | ||
| return "Shredded Mozzarella"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class Mushroom implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Mushrooms"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class Onion implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Onion"; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/factory/ingredient/ingredients/impl/ParmesanCheese.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Cheese; | ||
|
|
||
| public class ParmesanCheese implements Cheese { | ||
|
|
||
| public String toString() { | ||
| return "Shredded Parmesan"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Sauce; | ||
|
|
||
| public class PlumTomatoSauce implements Sauce { | ||
| public String toString() { | ||
| return "Tomato sauce with plum tomatoes"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class RedPepper implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Red Pepper"; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/factory/ingredient/ingredients/impl/ReggianoCheese.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Cheese; | ||
|
|
||
| public class ReggianoCheese implements Cheese { | ||
|
|
||
| public String toString() { | ||
| return "Reggiano Cheese"; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/factory/ingredient/ingredients/impl/SlicedPepperoni.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Pepperoni; | ||
|
|
||
| public class SlicedPepperoni implements Pepperoni { | ||
|
|
||
| public String toString() { | ||
| return "Sliced Pepperoni"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Veggies; | ||
|
|
||
| public class Spinach implements Veggies { | ||
|
|
||
| public String toString() { | ||
| return "Spinach"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Dough; | ||
|
|
||
| public class ThickCrustDough implements Dough { | ||
| public String toString() { | ||
| return "ThickCrust style extra thick crust dough"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package factory.ingredient.ingredients.impl; | ||
|
|
||
| import factory.ingredient.ingredients.Dough; | ||
|
|
||
| public class ThinCrustDough implements Dough { | ||
| public String toString() { | ||
| return "Thin Crust Dough"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package factory.pizza; | ||
|
|
||
| import factory.ingredient.ingredients.*; | ||
|
|
||
| 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(); | ||
|
Comment on lines
+5
to
+14
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| public void bake() { | ||
| System.out.println("175도에서 25분 간 굽기"); | ||
| } | ||
|
|
||
| public void cut() { | ||
| System.out.println("피자를 사선으로 자르기"); | ||
| } | ||
|
|
||
| public void box() { | ||
| System.out.println("상자에 피자 담기"); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String toString() { | ||
| StringBuilder result = new StringBuilder(); | ||
| result.append("---- ").append(name).append(" ----\n"); | ||
| if (dough != null) { | ||
| result.append(dough); | ||
| result.append("\n"); | ||
| } | ||
| if (sauce != null) { | ||
| result.append(sauce); | ||
| result.append("\n"); | ||
| } | ||
| if (cheese != null) { | ||
| result.append(cheese); | ||
| result.append("\n"); | ||
| } | ||
| if (veggies != null) { | ||
| for (int i = 0; i < veggies.length; i++) { | ||
| result.append(veggies[i]); | ||
| if (i < veggies.length-1) { | ||
| result.append(", "); | ||
| } | ||
| } | ||
| result.append("\n"); | ||
| } | ||
| if (clam != null) { | ||
| result.append(clam); | ||
| result.append("\n"); | ||
| } | ||
| if (pepperoni != null) { | ||
| result.append(pepperoni); | ||
| result.append("\n"); | ||
| } | ||
| return result.toString(); | ||
| } | ||
|
|
||
| public enum PizzaType { | ||
| CHEESE, | ||
| PEPPERONI | ||
| } | ||
| } | ||
Oops, something went wrong.
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.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
의존성 뒤집기 원칙(Dependency Inversion Priciple)을 활용하여
PizzaStore(고수준 구성 요소)가 가지는 피자 객체(저수준 구성 요소)에 대한 의존성을 없애기 위해
추상 팩토리 패턴을 활용한다.각 PizzStore 구상 클래스는 PizzaIngredientFactory를 통해 생성된 원재료를 세팅해주면 된다.
(PizzaIngredientFactory 또한 피자집의 성격에 맞는 구상 클래스를 구현해야한다.)
추상 팩토리 패턴