工厂模式之简单工厂
?
?
? ?简单工厂模式是属于创建型模式,又叫做静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模式之一。
? ? ?假如一个农场中FruitFactory生产Apple与Bananer两种水果,当农夫需要采集Apple时,则得到Apple,当需要采集Bananer时,得到Bananer,农场是负责农夫的请求返回想相应的水果。

?

?
?
?
?
?
?
? 先用C++来实现一次.
??#ifndef _FRUIT_H
?#ifndef _FRUITFACTORY_H
public class FactoryTest {/** * @param args */public static void main(String[] args) {try {Fruit apple = FruitFactory.getFruit("Apple");apple.get();} catch (Exception e) {e.printStackTrace();}}}?