java學習

          java學習

           

          設(shè)計模式之抽象工廠

          具體的水果工廠實現(xiàn)類具體的蘋果實現(xiàn)類具體的香蕉實現(xiàn)類具體的棗實現(xiàn)類
          中國水果工廠實現(xiàn)類中國蘋果中國香蕉中國棗
          日本水果工廠實現(xiàn)類日本蘋果日本香蕉日本棗
          以此類推,在工廠的接口中創(chuàng)建所有水果的方法聲明。
          public interface IFruit {
          public void get();
          }
          public abstract class AbstractApple implements IFruit{
          public abstract void get();
          }
          public abstract class AbstractBanana implements IFruit{
          public abstract void get();
          }
          public interface IFruitFactory {
          public IFruit getApple();
          public IFruit getBanana();
          }
          public class NorthApple extends AbstractApple {
          public void get() {
          System.out.println("北方蘋果");
          }
          }
          public class NorthBanana extends AbstractBanana {
          public void get() {
          System.out.println("北方香蕉");
          }
          }
          public class NorthFruitFactory implements IFruitFactory {
          public IFruit getApple() {
          return new NorthApple();
          }
          public IFruit getBanana() {
          return new NorthBanana();
          }
          }
          public class SouthApple extends AbstractApple {
          public void get() {
          System.out.println("南方蘋果");
          }
          }
          public class SouthBanana extends AbstractBanana {
          public void get() {
          System.out.println("南方香蕉");
          }
          }
          public class SouthFruitFactory implements IFruitFactory {
          public IFruit getApple() {
          return new SouthApple();
          }
          public IFruit getBanana() {
          return new SouthBanana();
          }
          }

          posted on 2017-09-01 17:04 楊軍威 閱讀(126) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           

          導航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 武冈市| 灵山县| 冀州市| 广河县| 青阳县| 鄂州市| 阿拉善左旗| 揭东县| 沙河市| 繁昌县| 黎平县| 壶关县| 岳西县| 海口市| 加查县| 徐水县| 宿迁市| 潜山县| 阿拉善左旗| 临猗县| 敖汉旗| 米泉市| 乃东县| 乐陵市| 安乡县| 磐安县| 宜兴市| 论坛| 山阳县| 商城县| 古交市| 娄底市| 柏乡县| 武鸣县| 莎车县| 永嘉县| 汨罗市| 晴隆县| 陵水| 阳原县| 苏尼特右旗|