Exemplo n.º 1
0
        private static void MakeMeABoatAbstractFactoryPattern()
        {
            string whatToMake             = "Sail Boat";
            AbstractBoatFactory factory   = null;
            IBoatColor          boatColor = null;

            if (whatToMake.Equals("Sail Boat"))
            {
                factory   = new SailBoatFactory();
                boatColor = factory.CreateBoatColor("Blue", true);
            }
            else
            {
                factory   = new MotorBoatFactory();
                boatColor = factory.CreateBoatColor("Green", false);
            }

            IBoatBody  boatBody  = factory.CreateBoatBody();
            IBoatMotor boatMotor = factory.CreateBoatMotor();

            //Show what was created
            Console.WriteLine(boatBody.BoatBodyStyle);
            Console.WriteLine(boatMotor.MotorSize);
            Console.WriteLine(boatColor.BoatColor);
        }
Exemplo n.º 2
0
        public string CreateSailBoat(string model, int weight, int sailEfficiency)
        {
            IBoat boat = SailBoatFactory.CreateBoat(model, weight, sailEfficiency);

            this.Database.Boats.Add(boat);

            return(string.Format("Sail boat with model {0} registered successfully.", model));
        }