工厂设计模式

实现创建者和调用者分离

//车

class Car{

private double price;

private double type;

}

//奔驰

class Benchi extends Car{

....

}

//奥迪

class Aodi extends Car{

....

}

//汽车工厂

interface CarFactory{

public Car createCar();

}

//奔驰工厂

class BenchiFactory implements CarFactory{

@Override

public Car createCar() {

System.out.println("制造奔驰");

return null;

}

}

//奥迪工厂

class AodiFactory implements CarFactory{

@Override

public Car createCar() {

System.out.println("制造宝马");

return null;

}

}

你可能感兴趣的:(工厂设计模式)