package test04;
public class BlackFactory implements Race{
@Override
public Women produceWoMan() {
return new BlackWoMen();
}
@Override
public Man produceMan() {
return new BlackMan();
}
}
package test04;
public class BlackMan implements Man{
@Override
public void sexIs() {
System.out.println("黑色男人");
}
}
package test04;
public class BlackWoMen implements Women{
@Override
public void sexIs() {
System.out.println("黑色女人");
}
}
package test04;
public class Client {
public static void main(String[] args) {
Race race = new YellowFactory();
Man man;
Women women;
man = race.produceMan();
man.sexIs();
women = race.produceWoMan();
women.sexIs();
}
}
package test04;
public interface Man{
public void sexIs();
}
package test04;
public interface Race {
public Women produceWoMan();
public Man produceMan();
}
package test04;
public class WhiteFactory implements Race{
@Override
public Women produceWoMan() {
return new WhiteWoMen();
}
@Override
public Man produceMan() {
return new WhiteMan();
}
}
package test04;
public class WhiteMan implements Man{
@Override
public void sexIs() {
System.out.println("白色男人");
}
}
package test04;
public class WhiteWoMen implements Women{
@Override
public void sexIs() {
System.out.println("白色女人");
}
}
package test04;
public interface Women{
public void sexIs();
}
package test04;
public class YellowFactory implements Race{
@Override
public Women produceWoMan() {
return new YellowWoMen();
}
@Override
public Man produceMan() {
return new YellowMan();
}
}
package test04;
public class YellowMan implements Man{
@Override
public void sexIs() {
System.out.println("黄色男人");
}
}
package test04;
public class YellowWoMen implements Women{
@Override
public void sexIs() {
System.out.println("黄色女人");
}
}