示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("general method");
            TeslaCar tesla = new TeslaCar();

            Console.WriteLine(tesla.Build());
            Console.WriteLine("---------------------------");

            Console.WriteLine("simple factory");
            CarFactory factory = new CarFactory();
            Car        audiCar = factory.CreateCar("Audi");

            Console.WriteLine(audiCar.Build());
            Console.WriteLine("---------------------------");

            Console.WriteLine("factory method");
            IFactory carFactory = new BenzFactory();
            Car      benZCar    = carFactory.CreateCar();

            Console.WriteLine(benZCar.Build());
            Console.WriteLine("---------------------------");

            Console.WriteLine("abstract factory");
            ICarFactory sportCarFactory = new SportCarFactory();
            ICar        benzSportCar    = sportCarFactory.GetBenzCar();
            ICar        teslaSportCar   = sportCarFactory.GetTeslaCar();

            benzSportCar.BuildCar();
            teslaSportCar.BuildCar();
            Console.ReadKey();
        }