<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    魚躍于淵

    First know how, Second know why !
    posts - 0, comments - 1, trackbacks - 0, articles - 49

    抽象工廠模式

    Posted on 2008-12-21 09:04 魚躍于淵 閱讀(125) 評論(0)  編輯  收藏 所屬分類: 設計模式

      1 package com.givetop.AbstractFactory;
      2 
      3 public class Factory {
      4     public static void main(String[] args){
      5         YangSheng ys = new YangSheng();
      6         Animal bull = null;
      7         bull = ys.getAnimal("Bull");
      8         bull.eat();
      9         bull.sleep();
     10     }
     11 }
     12 
     13 interface NWFactory{
     14     public Animal getAnimal(String type);
     15     public Person getPerson(String type);
     16 }
     17 
     18 class YangSheng implements NWFactory{
     19     Person man = null;
     20     Animal bull = null;
     21     public Animal getAnimal(String type){
     22         try {
     23             bull = (Bull)Class.forName("com.givetop.AbstractFactory."+type).newInstance();
     24         } catch (InstantiationException e) {
     25             e.printStackTrace();
     26         } catch (IllegalAccessException e) {
     27             e.printStackTrace();
     28         } catch (ClassNotFoundException e) {
     29             e.printStackTrace();
     30         }
     31         return bull;
     32     }
     33     public Person getPerson(String type){
     34         try {
     35             man = (Man)Class.forName("com.givetop.AbstractFactory."+type).newInstance();
     36         } catch (InstantiationException e) {
     37             e.printStackTrace();
     38         } catch (IllegalAccessException e) {
     39             e.printStackTrace();
     40         } catch (ClassNotFoundException e) {
     41             e.printStackTrace();
     42         }
     43         return man;
     44     }
     45 }
     46 
     47 class YinSheng implements NWFactory{
     48     Person woman = null;
     49     Animal cow = null;
     50     public Animal getAnimal(String type){
     51         try {
     52             cow = (Cow)Class.forName("com.givetop.AbstractFactory."+type).newInstance();
     53         } catch (InstantiationException e) {
     54             e.printStackTrace();
     55         } catch (IllegalAccessException e) {
     56             e.printStackTrace();
     57         } catch (ClassNotFoundException e) {
     58             e.printStackTrace();
     59         }
     60         return cow;
     61     }
     62     public Person getPerson(String type){
     63         try {
     64             woman = (Woman)Class.forName("com.givetop.AbstractFactory."+type).newInstance();
     65         } catch (InstantiationException e) {
     66             e.printStackTrace();
     67         } catch (IllegalAccessException e) {
     68             e.printStackTrace();
     69         } catch (ClassNotFoundException e) {
     70             e.printStackTrace();
     71         }
     72         return woman;
     73     }
     74 }
     75 
     76 interface Animal{
     77     public void eat();
     78     public void sleep();
     79 }
     80 
     81 interface Person{
     82     public void eat();
     83     public void sleep();
     84 }
     85 
     86 class Bull implements Animal{
     87     public void eat(){
     88         System.out.println("公牛開始吃東西了!");
     89     }
     90     public void sleep(){
     91         System.out.println("公牛開始睡覺了!");
     92     }
     93 }
     94 
     95 class Cow implements Animal{
     96     public void eat(){
     97         System.out.println("奶牛開始吃東西了!");
     98     }
     99     public void sleep(){
    100         System.out.println("奶牛開始睡覺了!");
    101     }
    102 }
    103 
    104 class Man implements Person{
    105     public void eat(){
    106         System.out.println("男人開始吃東西了!");
    107     }
    108     public void sleep(){
    109         System.out.println("男人要睡覺了!");
    110     }
    111 }
    112 
    113 class Woman implements Person{
    114     public void eat(){
    115         System.out.println("女人開始吃東西了!");
    116     }
    117     public void sleep(){
    118         System.out.println("女人要睡覺了!");
    119     }
    120 }

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


    網站導航:
     
    主站蜘蛛池模板: 国产乱子伦精品免费无码专区 | 免费永久看黄在线观看app| 亚洲AV无码久久| 亚洲欧洲视频在线观看| 国产亚洲精品AAAA片APP | 成人无码区免费A∨直播| 在线观看免费人成视频色| 亚洲午夜日韩高清一区| 亚洲av专区无码观看精品天堂| 日韩大片免费观看视频播放| 日本妇人成熟免费中文字幕| 日本亚洲视频在线 | 和老外3p爽粗大免费视频| 在线视频精品免费| 伊人久久大香线蕉亚洲五月天 | 免费观看激色视频网站bd| 国产精品亚洲αv天堂无码| sss日本免费完整版在线观看| 国产免费网站看v片在线| 国产性生交xxxxx免费| 亚洲国产精品久久网午夜 | 美景之屋4在线未删减免费| 1000部国产成人免费视频| 亚洲中文字幕久在线| 女人被男人桶得好爽免费视频| 久久精品国产亚洲麻豆| 毛片无码免费无码播放 | 2020年亚洲天天爽天天噜| 91短视频在线免费观看| 国产亚洲综合色就色| 国产免费区在线观看十分钟| 亚洲第一AAAAA片| 120秒男女动态视频免费| 亚洲日韩区在线电影| 免费人成黄页在线观看日本| 国产亚洲一区区二区在线| 一级毛片免费不卡| 久久亚洲精品成人av无码网站| 亚欧日韩毛片在线看免费网站| 亚洲AV午夜成人片| 成年人免费视频观看|