-
可扩展性不好
-
没有用到多态
-
Main.java
public class Main { public static void main(String[] args) { SimpleVehlicleFactory simpleFactory = new SimpleVehlicleFactory(); Car simpleCar = simpleFactory.createCar(); simpleCar.go(); } }
-
Car.java
public class Car { public void go() { System.out.println("Car go wuwuwuwuwu..."); } }
-
SimpleVehlicleFactory
/** * 简单工厂的可扩展性不好 */ public class SimpleVehlicleFactory { public Car createCar() { //before processing System.out.println("simple create!"); return new Car(); } public Broom createBroom() { return new Broom(); } }