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

            VehicleFactory factory = new VehicleFactory();

            int    numberOfWheels;
            string data;

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

            while (numberOfWheels > -1)
            {
                Console.WriteLine("Enter data");
                data = Console.ReadLine();

                Vehicle newVehicle = factory.CreateVehicle("Honda", 2000, "red", numberOfWheels, data);

                Console.WriteLine(newVehicle);

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

            Console.WriteLine("Good bye!");
        }
        static void Main(string[] args)
        {
            IVehicle autoMobile = VehicleFactory.CreateVehicle(Vehicle.AutoMobile);

            autoMobile.Start();
            autoMobile.Accelerate();
            autoMobile.Stop();

            VehicleFactory truckFactory = new VehicleFactory(Vehicle.Truck);
            IVehicle       truck        = truckFactory.CreateVehicle();

            truck.Start();
            truck.Accelerate();
            truck.Stop();

            VehicleFactory genericFactory = new VehicleFactory();

            genericFactory.VehicleType = Vehicle.AutoMobile;
            IVehicle autoFromGenericFactory = genericFactory.CreateVehicle();

            genericFactory.VehicleType = Vehicle.Truck;
            IVehicle truckFromGenericFactory = genericFactory.CreateVehicle();


            System.Console.WriteLine("\nVehicles from a generic factory");
            autoFromGenericFactory.Start();
            autoFromGenericFactory.Accelerate();
            autoFromGenericFactory.Stop();

            truckFromGenericFactory.Start();
            truckFromGenericFactory.Accelerate();
            truckFromGenericFactory.Stop();
        }
        static void Main(string[] args)
        {
            IVehicle v1 = VehicleFactory.CreateVehicle(VehicleTypes.Bus);
            IVehicle v2 = VehicleFactory.CreateVehicle(VehicleTypes.Car);

            v1.Move("Somewhere");
            v2.Move("In the world");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            IVehicle vehicle;

            vehicle = VehicleFactory.GetInctanse(VehicleFactory.Vehicles.Car);
            vehicle.SetSpeed(50);
            vehicle.Drive();

            vehicle = VehicleFactory.GetInctanse(VehicleFactory.Vehicles.Bus);
            vehicle.SetSpeed(50);
            vehicle.Drive();
        }
        static void Main(string[] args)
        {
            IVehicleFactory carCreator = new VehicleFactory();

            var car = carCreator.Build(CarType.Car);

            Console.WriteLine($"Car wheels count: {car.wheelsCount}");

            var motorbike = carCreator.Build(CarType.Motorbike);

            Console.WriteLine($"Motorbike wheels count: {motorbike.wheelsCount}");

            var truck = carCreator.Build(CarType.Truck);

            Console.WriteLine($"Truck wheels count: {truck.wheelsCount}");
        }
        static void Main(string[] args)
        {
            var factory = new VehicleFactory();

            IVehicle vehicle;

            factory.SetVehicleType(Vehicle.Car);

            vehicle = factory.GetVehicle();

            WriteVehicleInfo(vehicle);

            factory.SetVehicleType(Vehicle.SemiTruck);

            vehicle = factory.GetVehicle();

            WriteVehicleInfo(vehicle);

            Console.ReadLine();
        }