Java设计模式-工厂模式Java实现
工厂模式的java实现
代码地址:
简单工厂模式
pizza
Pizza.java
1 | package pizza; |
CheesePizza.java
1 | package pizza; |
ClamPizza.java
1 | package pizza; |
Factory
SimplePizzaFactory.java
1 | package Factory; |
Store
PizzaStore.java
1 | package Store; |
Customer.java
1 | import Factory.SimplePizzaFactory; |
输出
1 | Preparing Cheese Pizza |
工厂方法模式
Pizza
Pizza.java
1 | package Pizza; |
NYStyle
NYStyleCheesePizza.java
1 | package Pizza.NYStyle; |
NYStyleClamPizza.java
1 | package Pizza.NYStyle; |
ChicagoStyle
ChicagoStyleCheesePizza.java
1 | package Pizza.ChicagoStyle; |
ChicagoStyleClamPizza.java
1 | package Pizza.ChicagoStyle; |
Store
PizzaStore.java
1 | package Store; |
NYPizzaStore.java
1 | package Store; |
ChicagoPizzaStore.java
1 | package Store; |
Customer.java
1 | import Pizza.Pizza; |
输出
1 | --- Making a NY Style Sauce and Cheese Pizza --- |
抽象工厂模式
篇幅较长,只贴上部分代码
Ingredient
Cheese.java
1 | package Ingredient.Cheese; |
MozzarellaCheese.java
1 | package Ingredient.Cheese; |
ReggianoCheese.java
1 | package Ingredient.Cheese; |
IngredientFactory
ChicagoPizzaIngredientFactory.java
1 | package IngredientFactory; |
Pizza
CheesePizza.java
1 | package Pizza; |
Store
ChicagoPizzaStore.java
1 | package Store; |
Customer.java
1 | import Pizza.Pizza; |
输出
1 | --- Making a NY Style Sauce and Cheese Pizza --- |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 GreenHatHGのBlog!
评论