Example #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);
        }
Example #2
0
        private static void AbstractBoatFactoryPattern()
        {
            string whatToBuild          = "sailboat hull";
            AbstractBoatFactory factory = null;

            if (whatToBuild.Equals("sailboat hull"))
            {
                factory = new SailBoatFactory();
            }

            else
            {
                factory = new MotorBoatFactory();
            }

            IBoatHull  boatHull  = factory.CreateBoatHull();
            IBoatMotor boatMotor = factory.CreateBoatMotor();

            Console.WriteLine(boatHull.BoatHullParts);
            Console.WriteLine(boatMotor.BoatMotorParts);
        }
Example #3
0
 public AbstractMotorBoat(IBoatMotor engine, IBoatColor color, IBoatBody body)
     : base(engine, color, body)
 {
 }
Example #4
0
 public SailBoat(IBoatMotor engine, IBoatColor color, IBoatBody body)
     : base(engine, color, body)
 {
 }
 public AbstractBoat(IBoatMotor engine, IBoatColor color, IBoatBody body)
 {
     _engine    = engine;
     _boatColor = color;
     _body      = body;
 }