*/
public interface ICar{
//该类是定义创建汽车的相关方法,在这里暂不定义。
}
public class SimpleFactory{
public static final String TOPTYPE = "toptype";
public static final String MIDTYPE = "midtype";
public static final String LOWTYPE = "lowtype";
public static ICar create(String mark){
ICar obj = null;
if(mark.equals(TOPTYPE)){
obj = new TopCar();
System.out.println(TOPTYPE);
}
else if(mark.equals(MIDTYPE)){
obj = new TopCar();
System.out.println(MIDTYPE);
}
else if(mark.equals(LOWTYPE)){
obj = new TopCar();
System.out.println(LOWTYPE);
}
return obj;
}
}
public class TopCar implements ICar{
}
public class MidCar implements ICar{
}
public class LowCar implements ICar{
}
public class CarTest{
public static void main(String args[]){
ICar obj = SimpleFactory.create("toptype");
}
}