예제 #1
0
        private static void AbstractFactoryDemo()
        {
            /* Parent class object instance is created by its child class.
             * This parent class can only see methods that it created, that its child uses.
             * Any child types created, unless it was first created by the parent.*/

            AbstractBikeFactory factory = new RoadBikeFactory(); //used child object instance w/abstract parent

            /* Create the Bike parts
             * Interface object is created. The factory objects created above calls the method that returns the
             * interface that it is assigned to. These Created methods created a new object of a Frame or Seat.
             * This object can be of either Road or Mountain. In this case the RoadFrame and RoadSeat.*/

            // Interface Object  =  Object calling Constructor CreateBikeFrame from RoadBikeFactory

            IBikeFrame bikeFrame = factory.CreateBikeFrame();

            // CreateBikeSeat method of factory object @returns IBikeSeat to object bikeSeat
            IBikeSeat bikeSeat = factory.CreateBikeSeat();

            //Show what we created.

            /* Interface object bikeFrame calls the property BikeFrameParts
             * bikeFrame was created from the class RoadFrame. The property BikeFrameParts uses the get to
             * retur the string value from RoadFrame.*/

            Console.WriteLine(bikeFrame.BikeFrameParts);

            /* Interface object bikeSeat calls the property BikeSeatParts
             * bikeSeat was created from the class RoadSeat. The property BikeSeatParts uses the get to
             * return the string value from RoadSeat.*/

            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #2
0
        static void AbstractFactoryDemo()
        {
            AbstractBikeFactory factory = new RoadBikeFactory();

            // create the bike parts
            IBikeFrame bikeFrame = factory.CreateBikeFrame();
            IBikeSeat  bikeSeat  = factory.CreateBikeSeat();

            // Show what we created
            Console.WriteLine(bikeFrame.BikeFrameParts);
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #3
0
        private static void AbstractFactoryDemo()
        {
            /*
             * Parent class object instance is created by its child class. This parent class can only see
             * methods that it created, that its child ues. Any child types created, cannot be seen unless
             * it was first created by the parent.
             * This class object factory can only see the methods that it created, even from its child
             */
            AbstractBikeFactory factory = new RoadBikeFactory();   //RoadBikeFactory constructor from its child class

            /*
             * Create the Bike parts
             * Interface objects bikeFrame or bikeSeat are created. The "factory" object created
             * above calls the method that returns the interface to which it is assigned.
             * These Create methods create a new object of a Frame or Seat. This object can be of either
             * Road or Mountain. In this case, the new objects of RoadFrame and RoadSeat, are created inside the
             * RoadBikeFactory.
             */
            //This method returns an IBikeFrame (Method always has an open & closed parentheses)
            //Constructor is a class-level method, with no return type

            /*
             * CreateBikeFrame method
             * @returns IBikeFrame to object bikeFrame
             */
            /*
             * CreateBikeFrame method
             * @returns IBikeFrame to object bikeFrame
             */
            //interface objectofInterface = objectfromabove.method(); which is assigned from Right to Left
            IBikeFrame bikeFrame = factory.CreateBikeFrame();   // assigning that return value back to the interface
            IBikeSeat  bikeSeat  = factory.CreateBikeSeat();

            // Show what we created ... return back the properties through the interface object (above)... print it out

            /*
             * Interface object bikeFrame calls the property BikeFrameParts
             * bikeFrame was created from the class RoadFrame
             * The property BikeFrameParts uses the get to return
             * the string value from RoadFrame
             */
            /*
             * Interface object bikeSeat calls the property BikeSeatParts
             * bikeSeat was created from the class RoadSeat
             * The property BikeSeatParts uses the get to return
             * the string value from RoadSeat
             */
            Console.WriteLine(bikeFrame.BikeFrameParts);
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #4
0
        private static void AbstractFactoryDemo()
        {
            AbstractBikeFactory factory  = new RoadBikeFactory();
            AbstractBikeFactory factory1 = new MountainBikeFactory();

            IBikeFrame bikeFrame = factory.CreatBikeFrame();
            IBikeSeat  bikeSeat  = factory.CreatBikeseat();
            IBikeFrame bikeframe = factory1.CreatBikeFrame();
            IBikeSeat  bikeseat  = factory1.CreatBikeseat();

            Console.WriteLine(bikeFrame.BikeFrameParts);
            Console.WriteLine(bikeSeat.BikeSeatParts);
            Console.WriteLine(bikeframe.BikeFrameParts);
            Console.WriteLine(bikeseat.BikeSeatParts);
        }
예제 #5
0
        //Abstract Factory Design Pattern Demo Method
        private static void AbstractFactoryDemo()  //has to be static to call from main
        {
            /*
             * Parent class object instance is careated by its child
             * class. this parent class can only see methods that it
             * created, that its child uses. Any child types created,
             * cannot be seen unless it was first created by the parent.
             */
            AbstractBikeFactory factory = new RoadBikeFactory();

            /*Create the bike parts
             * Interface object is created. The factory objects created
             * above calls the method that returns the interface that it
             * is assinged to. These Create methods create a new object
             * of a Frame or Seat. This object can be of either Road or
             * Mountain. In this case the RoadFrame and RoadSeat.
             */

            /*
             * CreateBikeFrame method of factory object
             * @returns IBikeSeat to object bikeSeat
             */
            IBikeFrame bikeFrame = factory.CreateBikeFrame(); //"factory" is object, calling the method "CreateBikeFrame"

            /*
             * CreateBikeSeat method of factory object
             * @returns IBikeSeat to object bikeSeat
             */
            IBikeSeat bikeSeat = factory.CreateBikeSeat();

            /*Show what we created
             *
             * Interface object bikeFrame calls the property BikeFrameParts
             * bikeFrame was created from the class RoadFrame
             * The property BikeFrameParts uses the get to return
             * the string value from RoadFrame
             */
            Console.WriteLine(bikeFrame.BikeFrameParts);

            /*
             * Interface object bikeSeat calls the preoppty BikeSeatParts
             * bikeSeat was created from the class RoadSeat
             * The property BikeSeatParts uses the get to return
             * the string value from RoadSeat
             */
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #6
0
        private static void AbstractFactoryDemo()
        {
            /* parent class object instance is created by its child
             * class. this parebt class can only see methods that it created, that its child uses.
             * any child types created can not be seen unless it was first created  by parents.
             *
             */
            AbstractBikeFactory factory = new RoadBikeFactory();

            /* creat the bike parts
             * Interface object is created. the factory object is created
             * above calles the method that returns the interface that it is assigned to.
             * these creat methods creat a new object of a frame or seat. these object can be either road
             * mountain.in these case the roadframe and roadseat
             */


            IBikeFrame bikeframe = factory.CreatBikeFrame();

            //creatbikeframe method of factory object @ returns Ibikeframe to object bikeframe

            IBikeSeat bikeSeat = factory.CreatBikeSeat();

            //creatbikeseat method of factory object @ returns IBikeSeat to object bikeseat

            //shaw what we created , bikeframeparts and bikeseat parts are properties

            /*interface object bikeframe calls the property BikeFrameParts
             * bikeframe was created from the class bikeframe
             * the property bikeframeparts use the get to return
             * the string value from Bikefram
             */


            Console.WriteLine(bikeframe.BikeFrameParts);

            /*interface object bikeseat calls the property BikeseatParts
             * bikeseat was created from the class roadseat
             * the property bikeseatparts use the get to return
             * the string value from roadseat
             */
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #7
0
        private static void AbstractFactoryDemo()
        {
            /*parent class, creates objects of its child but not itself, because it is abstract, can't have a new instance
             * that it(parent) created, that it's child also uses. Any child types (methods, property) created by the child cannot be seen it was first created by the parent, parent can see something a child created but a parent can see */

            //this class can only see the othods it reated from its child
            //                           new constructor being called
            AbstractBikeFactory factory = new RoadBikeFactory();

            // create Bike parts, object of interface,
            //
            //interface object is bikeSeat, bikeFrame

            /* interface object is created. the factory object created calls the method that returns
             * the interface that is is assinged to. THe create methodes create a new object of a
             * Frame or Seat. This object can be either Road or Mountain. In this case the RoadFrame
             * and the RoadSeat.   factory object calls Create Methods, thta return an interface type*/

            // interface + object of interface = object, create Bikeseat is method
            // CreateBikeFrame is a method

            IBikeFrame bikeFrame = factory.CreateBikeFrame();
            IBikeSeat  bikeSeat  = factory.CreateBikeSeat();

            //*show what we created,  printing out the properties, return 2 properties from Roadbike

            /*thru interface object*
             * method () can have paramenters inside it , constructor = class level method, with no returntype
             * and use the class name
             * properties/
             * interface object bikeFrame calls the property BikeFrameParts
             * bikeFrame was created from the class RoadFrame
             * the property Bikeframeparts uses the get to return the string value from RoadFrame
             */
            Console.WriteLine(bikeFrame.BikeFrameParts);

            /*interface object bikeSeat calls the property BikeFrameParts
             * bikeSeat was created from the class RoadSeat
             * the property BikeSeatParts uses the get to return the string value from RoadSeat
             */

            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #8
0
        private static void AbstractFactoryDemo()
        {
            /*
             * parent class object instance is created by its child class. this parent class can only see method that it created, that its child uses.
             * any child types created, cannot be seen unless it was first created by the parent.
             */
            AbstractBikeFactory factory = new RoadBikeFactory();

            /*
             * create bike parts
             * Interface object is created. The factory objects created above calls the method that returns the interface that it is assigned to. These create methods create
             * a new object of a Frame or Seat. This object can be of either road or mountain. In this case the roadframe and roadseat.
             */
            IBikeFrame bikeFrame = factory.CreateBikeFrame();
            IBikeSeat  bikeSeat  = factory.CreateBikeSeat();

            //show what we created
            Console.WriteLine(bikeFrame.BikeFrameParts);
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #9
0
        private static void AbstractFactoryDemo()
        {/*
          * parent class object is created by its child class.
          * This parent class can only see methods that it created.
          * It gets all child class types that IT created
          * (new methods of child class are not used).
          */
            AbstractBikeFactory factory = new RoadBikeFactory();

            /*create the bike parts
             * interface object is created and it calls the factory method that
             * returns that interface. This method creates a new object instance
             * of the Frame or Seat class. These classes implement the calling interface
             */
            IBikeFrame bikeFrame = factory.CreateBikeFrame();
            IBikeSeat  bikeSeat  = factory.CreateBikeSeat();

            //show what we created
            Console.WriteLine(bikeFrame.BikeFrameParts);
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
예제 #10
0
        private static void AbstractFactoryDemo()
        {
            /* Parent class object instance is created byt its child class.
             * This parent class can only see methods, or types that it creates and the child class uses.
             * Any methods or types created by the child cannot be seen unless it was first created by the parent.
             */
            AbstractBikeFactory factory = new RoadBikeFactory();

            /*Create Bike Parts
             * Interface object is created. The factory  objects created above calls
             * the method that returns the intereface that it is assigned to. These
             * Create methods create a new object of a Frame or Seat. This object
             * can be either Road or Mountain. In this case the RoadFrame and RoadSeat.
             */
            IBikeFrame bikeFrame = factory.CreateBikeFrame();
            IBikeSeat  bikeSeat  = factory.CreateBikeSeat();

            /*Show what we created
             *
             */
            Console.WriteLine(bikeFrame.BikeFrameParts);
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }
        private static void AbstractFactoryDemo()
        {
            //parent calss object instance is created by its child class.
            //the parent class can olny see method that is created that its child us. any child types
            //created can not be seen unless it was first created by the parent.



            AbstractBikeFactory factory   = new RoadBikeFactory();
            IBikeFrame          bikeFrame = factory.CreateBikeFrame();
            //create bike seat method of factory object @return IBikeseat to object bikeseat
            //create the Bike part


            IBikeSeat bikeSeat = factory.CreateBikeSeat();

            //create Bikeseat method of factory object @return IBikeseat to object bikeseat

            // shaow what we created and interface object calls the property Bikeseatparts
            //bikeseat was created from the class roadseat
            //the propeerty of bikeseatparts uses the get to return the string value from roadseat.
            Console.WriteLine(bikeFrame.BikeFrameParts);// this is properties
            Console.WriteLine(bikeSeat.BikeSeatParts);
        }