人与肤色

 

使用抽象工厂模式,完成下述产品等级结构: 

实验要求:

1.  画出对应的类图;

 

 

2.  提交源代码;

  Man.java

public interface Man {

public void makeM();

}

WhiteMan.java

public class WhiteMan implements Man {

public void makeM() {

    System.out.println("我是白种男人!");

}

}

public class YellowMan implements Man {

public void makeM() {

    System.out.println("我是黄种男人!");

}

}

public class BlackMan implements Man {

@Override

public void makeM() {

    System.out.println("我是黑种男人!");

}

}

public interface Woman {

public void makeW();

}

 

public class WhiteWoman implements Woman {

@Override

public void makeW() {

    System.out.println("我是白种女人!");

}

}

public class YellowWoman implements Woman {

   public void makeW() {

      System.out.println("我是黄种女人!");

   }

}

public class BlackWoman implements Woman {

   @Override

   public void makeW() {

      System.out.println("我是黑种女人!");

   }

}

public interface Color {

 public Man produceMan();

 public Woman produceWoman();

}

public class White implements Color{

   @Override

   public Man produceMan() {

      return new WhiteMan();

   }

   @Override

   public Woman produceWoman() {

      return new WhiteWoman();

   }

}

public class Yellow implements Color{

   @Override

   public Man produceMan() {

      return new YellowMan();

   }

   @Override

   public Woman produceWoman() {

      return new YellowWoman();

   }

}

public class Black implements Color{

   @Override

   public Man produceMan() {

      return new BlackMan();

   }

   @Override

   public Woman produceWoman() {

      return new BlackWoman();

   }

}

posted @ 2024-10-28 21:42  涨涨涨张  阅读(4)  评论(0编辑  收藏  举报