コード例 #1
0
ファイル: Program.cs プロジェクト: shawcoder/DotNetNewbies
        static void Main()
        {
            // Econical car, blue
            VehicleFactory vCarFactory = new CarFactory();
            IVehicle       vCar        = vCarFactory.Build
                                             (VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue);

            WriteLine(vCar);

            // White van
            VehicleFactory vVanFactory = new VanFactory();
            IVehicle       vVan        = vVanFactory.Build
                                             (VehicleFactory.DrivingStyle.Powerful, VehicleColour.White);

            WriteLine(vVan);

            // Red Sports car using static factory
            IVehicle vSportsVehicle =
                VehicleFactory.Make
                (
                    VehicleFactory.BuildWhat.Car
                    , VehicleFactory.DrivingStyle.Powerful
                    , VehicleColour.Red
                );

            WriteLine(vSportsVehicle);

            ReadKey();
        }
コード例 #2
0
        public Sample()
        {
            VehicleFactory carFactory = new CarFactory();

            carFactory.Build(VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue);

            VehicleFactory vanFactory = new VanFactory();

            vanFactory.Build(VehicleFactory.DrivingStyle.Economical, VehicleColour.Silver);
        }
コード例 #3
0
        public void CarFactoryMethodTest()
        {
            //given
            VehicleFactory carFactory = new CarFactory();

            //When
            IVehicle car = carFactory.Build(VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue);

            //then
            Assert.AreEqual(car.GetType(), typeof(Saloon));
        }
コード例 #4
0
        /// <summary>
        /// The Client
        /// </summary>
        static void Main(string[] args)
        {
            var superBuilder    = new SuperCarBuilder();
            var notSuperBuilder = new NotSoSuperCarBuilder();

            var factory  = new CarFactory();
            var builders = new List <CarBuilder> {
                superBuilder, notSuperBuilder
            };

            foreach (var b in builders)
            {
                var c = factory.Build(b);
                Console.WriteLine($"The Car requested by " +
                                  $"{b.GetType().Name}: " +
                                  $"\n--------------------------------------" +
                                  $"\nHorse Power: {c.HorsePower}" +
                                  $"\nImpressive Feature: {c.MostImpressiveFeature}" +
                                  $"\nTop Speed: {c.TopSpeedMPH} mph\n");
            }
        }
コード例 #5
0
 public void BuildMicroCar(Location location)
 {
     _carFactory.Build(CarType.MICRO, location);
 }
コード例 #6
0
ファイル: Factory.cs プロジェクト: walrus7521/code
        public static void Main()
        {
            // I want an economical car, coloured blue
            VehicleFactory carFactory = new CarFactory();
            IVehicle car = carFactory.Build(
                                VehicleFactory.DrivingStyle.Economical,
                                VehicleColour.Blue);
            Console.WriteLine(car);

            // I want a "white van"
            VehicleFactory vanFactory = new VanFactory();
            IVehicle van = vanFactory.Build(
                                VehicleFactory.DrivingStyle.Powerful,
                                VehicleColour.White);
            Console.WriteLine(van);

            // use the static Make method to create a red sports car
            IVehicle sporty = VehicleFactory.Make(
                                VehicleFactory.Category.Car,
                                VehicleFactory.DrivingStyle.Powerful,
                                VehicleColour.Red);
            Console.WriteLine(sporty);
        }