コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }