package creational;

/**
 * Created by 李恒名 on 2017/6/14.
 * <p>
 * 简单工厂模式
 */
public class SimpleFactoryPattern {
    //汽车抽象
    static abstract class Car {
        abstract void run();
    }
    //奔驰汽车
    static class Benz extends Car {

        @Override
        void run() {
            System.out.println("奔驰车在跑");
        }
    }
    //宝马汽车
    static class BMW extends Car {

        @Override
        void run() {
            System.out.println("宝马车在跑");
        }
    }
    //汽车工厂，根据汽车名称创建汽车
    static class CarFactory {
        Car getCar(String name) {
            if (name.equals("Benz")) {
                return new Benz();
            } else if (name.equals("BMW")) {
                return new BMW();
            } else {
                throw new IllegalArgumentException("No support this car");
            }
        }
    }

    public static void main(String[] args) {
        CarFactory factory = new CarFactory();
        Car car = factory.getCar("Benz");
        //Car car = factory.getCar("BMW");
        car.run();
    }
}


@@ -66,17 +66,67 @@
 * %E7%AE%80%E5%8D%95%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F
+%EF%BC%8C%E7%AE%80%E5%8D%95%E6%9D%A5%E8%AF%B4%E5%B0%B1%E6%98%AF%E7%94%B1%E4%B8%80%E4%B8%AA%E5%B7%A5%E5%8E%82%E7%B1%BB%E6%A0%B9%E6%8D%AE%E4%BC%A0%E5%85%A5%E7%9A%84%E5%8F%82%E6%95%B0%EF%BC%8C%E5%8A%A8%E6%80%81%E5%86%B3%E5%AE%9A%E5%BA%94%E8%AF%A5%E5%88%9B%E5%BB%BA%E5%93%AA%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%E7%B1%BB%EF%BC%88%E8%AF%A5%E6%A8%A1%E5%BC%8F%E5%B9%B6%E4%B8%8D%E5%B1%9E%E4%BA%8EGOF 23%EF%BC%89
 %0A
-
  */%0Apubl
@@ -274,33 +274,32 @@
 z extends Car %7B%0A
-%0A
         @Overrid
@@ -389,16 +389,16 @@
  //%E5%AE%9D%E9%A9%AC%E6%B1%BD%E8%BD%A6%0A
+
     stat
@@ -424,17 +424,16 @@
 s Car %7B%0A
-%0A
         

update > 简单工厂模式