1.创建产品接口(所有产品的特性都在)
public interface Human {
public void getColor();
public void talk();
public void getSex();
}
2.创建抽象的产品类,实现产品接口(某一款产品的共性)
public abstract class AbstractBlackHuman implements Human {
@Override
public void getColor() {
System.out.println("黑人");
}
@Override
public void talk() {
System.out.println("讲英文");
}
}
3.创建具体产品类(具体产品的特性)
public class FemaleBlackHuman extends AbstractBlackHuman {
@Override
public void getSex() {
System.out.println("男黑人");
}
}
4.创建工厂接口(整个工厂)
public interface FactoryHuman {
public Human createBlackHuman();
public Human createWhilteHuman();
public Human createYellowHuman();
}
5.创建具体工厂类(一个工程的不同车间的具体生产的产品)
public class FemaleHumanFactory implements FactoryHuman {
@Override
public Human createBlackHuman() {
// TODO Auto-generated method stub
return new FemaleBlackHuman();
}
@Override
public Human createWhilteHuman() {
// TODO Auto-generated method stub
return new FemaleWhilteHuman();
}
@Override
public Human createYellowHuman() {
// TODO Auto-generated method stub
return new FemaleYellowHuman();
}
}