<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 魚躍于淵 閱讀(128) 評論(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 }

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲日韩国产精品第一页一区| 亚洲精品无码av天堂| 成人毛片18女人毛片免费| 免费国产综合视频在线看 | 污污的视频在线免费观看| 日本xxxx色视频在线观看免费| 在线精品免费视频无码的| 国产AV无码专区亚洲精品| 亚洲Av永久无码精品一区二区| 国产精品白浆在线观看免费 | 一级毛片aaaaaa免费看| 四虎永久在线精品免费影视| 亚洲永久永久永久永久永久精品| 国产天堂亚洲国产碰碰| 18禁美女裸体免费网站| 亚洲女人被黑人巨大进入| 一区二区三区免费高清视频| 夭天干天天做天天免费看| 亚洲AV日韩综合一区| 亚洲AⅤ无码一区二区三区在线 | 亚洲av日韩aⅴ无码色老头| 国产成人一区二区三区免费视频| 亚洲精品亚洲人成在线麻豆| 不卡视频免费在线观看| 四虎影视永久免费观看地址| 曰批免费视频播放免费 | 亚洲字幕在线观看| 成在人线av无码免费高潮喷水| 国产无遮挡又黄又爽免费视频| 日日狠狠久久偷偷色综合免费 | 亚洲第一福利网站| 国产裸体美女永久免费无遮挡| 国产一区视频在线免费观看| 天堂亚洲免费视频| 亚洲一区二区三区高清| 午夜免费福利影院| 亚洲色大成WWW亚洲女子| 国产精品无码免费播放| 亚洲三级视频在线| 国产成人精品久久免费动漫| 亚洲福利电影一区二区?|