示例#1
0
        static void Main(string[] args)
        {
            CarBuilder  builder     = new BMWBuilder();
            CarDirector carDirector = new CarDirector(builder);

            carDirector.CreatCar();
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            AbstractCar     car      = new Saloon(new TurboEngine(1500), VehicleColour.Blue);
            VehicleBuilder  builder  = new CarBuilder(car);
            VehicleDirector director = new CarDirector();
            IVehicle        v        = director.Build(builder);

            Console.WriteLine(v);
            Console.Read();
        }
示例#3
0
        public static void Main(string[] args)
        {
            CorsaBuilder corsaBuilder = new CorsaBuilder("Korsina");
            CarDirector  director     = new CarDirector(corsaBuilder);

            director.makeCar();
            Car car = director.GetCar();

            Console.WriteLine(car.engine.Type);
            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            //向左制造引擎,颜色
            AbstractCar    car     = new Saloon(new StandardEngine(1300));
            VehicleBuilder Builder = new CarBuilder(car);
            //向右制造汽车框架结构
            VehicleDirector director = new CarDirector();

            Console.WriteLine(director.Build(Builder));
            Console.Read();
        }
示例#5
0
        static void Main(string[] args)
        {
            CarDirector director = new CarDirector();

            //1辆A类型的奔驰车
            for (int i = 0; i < 1; i++)
            {
                director.getABenzModel().run();
            }

            //10辆B类型的奔驰车
            for (int i = 0; i < 10; i++)
            {
                director.getBBenzModel().run();
            }
            Console.ReadLine();
        }
示例#6
0
        static void Main(string[] args)
        {
            CarBuilder  cb1 = new BenzBuilder();
            CarDirector cd1 = new CarDirector(cb1);

            cd1.createCar();
            Car c1 = cb1.getCar();

            c1.show();
            CarBuilder cb2 = new BMWBuilder();

            cd1.setBuilder(cb2);
            cd1.createCar();
            Car c2 = cb2.getCar();

            c2.show();
            Console.WriteLine(c1.Equals(c2));
            Console.Read();
        }
示例#7
0
        static void Main()
        {
            CarBuilder basicCarBuilder = new BasicCarBuilder();
            CarBuilder superCarBuilder = new SuperCarBuilder();

            List <CarBuilder> builders = new List <CarBuilder>()
            {
                basicCarBuilder,
                superCarBuilder
            };

            CarDirector director = new CarDirector();

            foreach (CarBuilder builder in builders)
            {
                Car car = director.Build(builder);
                Console.WriteLine($"Car Built By: {builder.GetType().Name}");
                Console.WriteLine($"Top Speed: {car.TopSpeed}");
                Console.WriteLine($"Horse Power: {car.HorsePower}");
                Console.WriteLine();
            }

            Console.Read();
        }