protected virtual void LoadModules(IChassis chassis = null, IEngine engine = null, IRadio radio = null, ITurret turret = null, IGun gun = null)
        {
            this.BeginChangeModules();

            if (engine != null)
            {
                this.LoadEngine(engine, false);
            }

            if (radio != null)
            {
                this.LoadRadio(radio, false);
            }

            if (turret != null)
            {
                this.LoadTurret(turret, gun == null, false);
            }

            if (gun != null)
            {
                this.LoadGun(gun, turret == null, false);
            }

            if (chassis == null)
            {
                this.TryUpgradeChassis();
            }
            else
            {
                this.LoadChassis(chassis);
            }

            this.EndChangeModules();
        }
Exemple #2
0
        /// <summary>
        /// 'Client' Application
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            string whatToMake = "car"; // or "van"

            AbstractVehicleFactory factory = null;

            // Create the correct 'factory'...
            if (whatToMake.Equals("car"))
            {
                factory = new CarFactory();
            }
            else
            {
                factory = new VanFactory();
            }

            // Create the vehicle's component parts...
            // These will either be all car parts or all van parts
            IBody      vehicleBody      = factory.CreateBody();
            IChassis   vehicleChassis   = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            // Show what we've created...
            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleGlassware.GlasswareParts);
            Console.Read();
        }
Exemple #3
0
 public CarWorld(ICarFactory carFactory)
 {
     _carFactory = carFactory;
     _engine     = _carFactory.CreateEngine();
     _chassis    = _carFactory.CreateChassis();
     _wheel      = _carFactory.CreateWheel();
 }
        static void Main(string[] args)
        {
            // the client can instantiate the appropriate
            // 'factory' with which it can obtain the correct
            // parts, whether for car or van

            string whatToMake = "car";

            AbstractVehicleFactory factory = null;

            // create the correct factory
            if (whatToMake.Equals("car"))
            {
                factory = new CarFactory();
            }
            else if (whatToMake.Equals("van"))
            {
                factory = new VanFactory();
            }

            // create the vehicle component parts...
            IBody      body    = factory.CreateBody();
            IChassis   chassis = factory.CreateChassis();
            IGlassware glass   = factory.CreateGlassware();

            // see what we have created
            Console.WriteLine(body.BodyParts);
            Console.WriteLine(chassis.ChassisParts);
            Console.WriteLine(glass.GlasswareParts);
            Console.ReadLine();

            // disadvantage: if adding a new product ex. Lights, to include lights in family of components
            //              would need to amend AbstractVehicleFactory, CarFactory, VanFactory
            //              in addition new ILights (CarLights/Vanlights) will need to be created
        }
 public Client1(IAutoFactory factory_)
 {
     body_    = factory_.CreateIBody();
     cabin_   = factory_.CreateICabin();
     chassis_ = factory_.CreateIChassis();
     engine_  = factory_.CreateIEngine();
 }
Exemple #6
0
        /*
         *      Implementation details:
         *      - Start with interface
         *      - Add "functionality" using virtual properties in the abstract class
         *
         *      - Downside of Abstract Factory pattern:
         *      - If new functionality is needed (e.g. Trailer Hitch parts), then that
         *              functionality must be added using the same (pardon the pun) pattern
         *              e.g. Add the interface, then add the abstract class, then add the
         *              functionality where necessary by modifying the appropriate factory
         *              method.
         */
        static void Main()
        {
            WhatToMake             WHAT_VEHICLE_TO_MAKE = WhatToMake.Car;
            AbstractVehicleFactory vFactory;

            switch (WHAT_VEHICLE_TO_MAKE)
            {
            case WhatToMake.Car:
            {
                vFactory = new CarFactory();
                break;
            }

            case WhatToMake.Van:
            {
                vFactory = new VanFactory();
                break;
            }

            default:
            {
                throw new Exception("Unhandled vehicle type selected!");
            }
            }
            IBody      vBody      = vFactory?.CreateBody();
            IChassis   vChassis   = vFactory?.CreateChassis();
            IGlassware vGlassware = vFactory?.CreateGlassware();

            WriteLine(vBody.BodyParts);
            WriteLine(vChassis.ChassisParts);
            WriteLine(vGlassware.GlasswareParts);
            ReadKey();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            string whatToMake = "van"; // or "van"
            AbstractVehicleFactory factory = null;

            // Create the correct 'factory'...
            if (whatToMake.Equals("car"))
            {
                factory = new CarFactory();
            }
            else
            {
                factory = new VanFactory();
            }

            // Create the vehicle parts, either a car or a van...
            IBody      vehicleBody      = factory.CreateBody();
            IChassis   vehicleChassis   = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            // See what we've created...
            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleGlassware.GlasswareParts);

            Console.Read();
        }
Exemple #8
0
        public void Get_Returns_Body_Shell_For_Car()
        {
            Vehicle vehicle = new Vehicle();
            AbstractVehicleFactory vehicleFactory = vehicle.Get(VehicleType.Car);
            IChassis vehicleChassis = vehicleFactory.CreateChassis();

            Assert.AreEqual <string>(vehicleChassis.ChassisParts, "Chassis parts for a car");
        }
Exemple #9
0
        public void VanFactoryTests()
        {
            AbstractVehicleFactory factory = new VanFactory();

            IBody      vehicleBody      = factory.CreateBody();
            IChassis   vehicleChassis   = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            Assert.AreEqual(expected: "Body shell parts for a van", actual: vehicleBody.BodyParts);
            Assert.AreEqual(expected: "Chassis parts for a van", actual: vehicleChassis.ChassisParts);
            Assert.AreEqual(expected: "Window glassware for a van", actual: vehicleGlassware.GlasswareParts);
        }
        public void VanFactoryTest()
        {
            //given
            AbstractVehicleFactory factory = new VanFactory();

            //when
            IBody      vehicleBody      = factory.CreateBody();
            IChassis   vehicleChasis    = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            //then
            Assert.AreEqual(vehicleBody.GetType(), typeof(VanBody));
            Assert.AreEqual(vehicleChasis.GetType(), typeof(VanChassis));
            Assert.AreEqual(vehicleGlassware.GetType(), typeof(VanGlassware));
        }
Exemple #11
0
        static void Main(string[] args)
        {
            string whatToMake = "car";
            AbstractVehicleFactory factory = null;

            if (whatToMake.Equals("car"))
            {
                factory = new CarFactory();
            }
            else
            {
                factory = new VanFactory();
            }

            IBody      vehicleBody      = factory.CreateBody();
            IChassis   vehicleChassis   = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleGlassware.GlasswarePart);
            Console.ReadKey();
        }
 internal virtual void LoadChassis(IChassis chassis)
 {
     this.BeginChangeModules();
     this.LoadedModules.Chassis = this.AvailableChassis[chassis];
     this.EndChangeModules();
 }
 public bool IsEliteModule(IChassis chassis)
 {
     return(chassis == this.Tank.AvailableChassis.Values.Last());
 }