コード例 #1
0
ファイル: Client.cs プロジェクト: phoenixproject/csdpe
        static void Main()
        {
            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();
            IWindows vehicleWindows = factory.CreateWindows();

            // Show what we've created...
            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleWindows.WindowParts);
            Console.Read();
        }
コード例 #2
0
        public void Main()
        {
            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();
            IWindows vehicleWindows = factory.CreateWindows();

            // Show what we've created...
            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleWindows.WindowParts);
            Console.Read();
        }