Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to my factory!");

            VehicleFactory factory = new VehicleFactory();

            int numberOfWheels = 0;

            Console.Write("Enter number of wheels: ");
            numberOfWheels = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter Special data: ");
            string specielData = Console.ReadLine();

            while (numberOfWheels > -1)
            {
                Vehicle newVehicle = factory.CreateVehicle("Honda", 2000, "red", numberOfWheels, specielData);

                Console.WriteLine(newVehicle);

                Console.Write("Enter number of wheels: ");
                numberOfWheels = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter Special data: ");
                specielData = Console.ReadLine();
            }

            Console.WriteLine("Good bye!");

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // I want an economical car, coloured blue...

            VehicleFactory carFactory = new CarFactory();
            IVehicle       car        = carFactory.Build(DrivingStyle.Economical,  VehicleColour.Blue);

            Console.WriteLine(car);  

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

            Console.WriteLine(van);

            // USING STATIC FACTORY

            // Create a red sports car...
            IVehicle sporty = VehicleFactory.Make(Category.Car,
                                                  DrivingStyle.Powerful,
                                                  VehicleColour.Red);

            Console.WriteLine(sporty);

            Console.Read();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var vehicleFactory = new VehicleFactory();

            var car        = vehicleFactory.GetVehicle(VehicleType.Car);
            var motorcycle = vehicleFactory.GetVehicle(VehicleType.Motorcycle);

            Console.WriteLine($"{car.VehicleType.ToString()} - {car.Capacity} - {car.TopSpeed} - {car.Price}");
            Console.WriteLine($"{motorcycle.VehicleType.ToString()} - {motorcycle.Capacity} - {motorcycle.TopSpeed} - {motorcycle.Price}");
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var vehicleFactory = new VehicleFactory();

            IVehicle vehicleCar = vehicleFactory.ProduceVehicle(VehicleType.Car);

            vehicleCar.DisplayInfo();

            IVehicle vehicleMotorcycle = vehicleFactory.ProduceVehicle(VehicleType.Motorcycle);

            vehicleMotorcycle.DisplayInfo();
        }
Exemple #5
0
        static void Main()
        {
            var vehickeFactory = new VehicleFactory();

            var scooter = vehickeFactory.GetVehicle("Scooter");

            scooter.Drive(20);

            var bike = vehickeFactory.GetVehicle("Bike");

            bike.Drive(50);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var factory = VehicleFactory.CreateVehicle("carro");
            var vehicle = factory.GetVehicle("Fusca");

            Console.WriteLine(vehicle.PickUp("Gustavo"));
            Console.WriteLine(vehicle.Stop());

            factory = VehicleFactory.CreateVehicle("bicicleta");
            vehicle = factory.GetVehicle("Bike");
            Console.WriteLine(vehicle.PickUp("Gustavo"));
            Console.WriteLine(vehicle.Stop());
        }
        public static IVehicle Make(Category category, DrivingStyle style, VehicleColour colour)
        {
            VehicleFactory factory = null;

            if (category == Category.Car)
            {
                factory = new CarFactory();
            }
            else
            {
                factory = new VanFactory();
            }

            return(factory.Build(style, colour));
        }
Exemple #8
0
        static void Main(string[] args)
        {
            VehicleFactory carFactory = new CarFactory();
            IVehicle       car        = carFactory.Build(VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue);

            Console.WriteLine(car);

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

            Console.WriteLine(van);

            IVehicle sporty = VehicleFactory.Make(VehicleFactory.Category.Car, VehicleFactory.DrivingStyle.Powerful, VehicleColour.Red);

            Console.WriteLine(sporty);

            Console.Read();
        }
Exemple #9
0
        public static IVehicle Make
        (
            BuildWhat aBuildWhat
            , DrivingStyle aDrivingStyle
            , VehicleColour aVehicleColour
        )
        {
            switch (aBuildWhat)
            {
            case BuildWhat.Car:
            {
                Factory = new CarFactory();
                break;
            }

            case BuildWhat.Van:
            {
                Factory = new VanFactory();
                break;
            }
            }
            return(Factory.Build(aDrivingStyle, aVehicleColour));
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var vehicleFactory = new VehicleFactory();

            IVehicle v1 = vehicleFactory.ProduceVehicle(VehicleType.Car);

            v1.DisplayInfo();
            v1.getNumber();

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

            IVehicle v2 = vehicleFactory.ProduceVehicle(VehicleType.Motorcycle);

            v2.DisplayInfo();
            v2.getNumber();

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

            IVehicle v3 = vehicleFactory.ProduceVehicle(VehicleType.Ship);

            v3.DisplayInfo();
            v3.getNumber();
        }