abstract class Fruit{
}
class Apple extends Fruit{
}
class Orange extends Fruit{
}
class FruitFactory{
pulic static Fruit getFruit(String fruitType){
if (“apple” == fruitType){
return new Apple();
} else if (“orange” == fruitType) {
return new Orange();
}
}
}
简单工厂模式
最新推荐文章于 2025-05-26 21:02:41 发布