工厂方法-抽象工厂
工厂方法就是定制
public class car{ public void go(){ System.out.println("Car go"); } Car c = new car(); c.go(); } public class Plane(){ public void go(){ System.out.println("Plane go"); } } public class Broom implements Moveable{ public void go(){ System.out.println("Broom go"); } } public class VehicleFactory{ publc Car createCar(){ // coding return new Car(); } public Broom createBroom(){ return new Broom(); } } public class CarFactory{ publc Car createCar(){ // coding return new Car(); } public Broom createBroom(){ return new Broom(); } } public class Weapon{ } public class Bread{ } public abstract class AbstractFactory{ abstract Food createFood(); abstract Vehilce createVehicle(); abstract Weapon createWeapon(); } public class ModernFactory extends AbstractFactory{ Fool createFood(){ return new Bread(); } Vehicle createVehicle(){ return new Vehicle(); } Weapon createWeapon(){ return new Weapon(); } } public class Main(){ public static void main(String[] args){ Moveable m = new Broom(); m.go(); Plane plane = new Plane(); p.go(); Moveable m = new CarFactory().createCar(); m.go(); AbstractFactory f = new ModernFacory(); } }
论读书
睁开眼,书在面前 闭上眼,书在心里
睁开眼,书在面前 闭上眼,书在心里