ITeye博客

设计模式快速参考-简单工厂模式

gurudk · 2008-12-06 06:40 · 模式 · 设计模式 · Apple · Markdown

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();
      }
   }
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。