java GOF23设计模式-简单工厂模式
作者:互联网
public class CarFactory {
//简单工厂模式1
public Car createCar(String type)
{
if(type.equals("奥迪"))
{
return new Audi();
}else if(type.equals("比亚迪"))
{
return new Byadi();
}
return null;
}
//或简单工厂模式2
public static Car createAudi()
{
return new Audi();
}
public static Car createByadi()
{
return new Byadi();
}
}
标签:return,GOF23,Car,static,new,java,设计模式,type,public 来源: https://blog.51cto.com/14437184/2440411