简单工厂
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();
}
}
}
Client:
Apple apple = FruitFactory.getFruit(“apple”);
...