gpt4 book ai didi

java - 工厂方法 VS 工厂对象

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:26:05 24 4
gpt4 key购买 nike

<分区>

据我了解工厂方法是简单工厂而工厂对象是抽象工厂?并且:

-工厂方法(简单工厂):

public class SimplePizzaFactory {
public static final int CHEESE = 1;
public static final int PEPPERONI = 2;
public static final int VEGGIE = 3;

public static Pizza createPizza(int type) {
Pizza pizza = null;

if (type == CHEESE) {
pizza = new CheesePizza();
} else if (type == PEPPERONI ) {
pizza = new PepperoniPizza();
} else if (type == VEGGIE ) {
pizza = new VeggiePizza();
}

return pizza;
}
}

工厂对象(抽象工厂):

?

我说得对吗?

工厂模式有多少实现,它们有什么区别?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com