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();
}
}
原文地址:https://blog.51cto.com/14437184/2440411
时间: 2024-10-13 05:30:43