コード例 #1
0
        static void Main(string[] args)
        {
            string whatToMake = "car"; // or "van"

            AbstractVehicleFactory factory = null;

            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();
            IGlassware vehicleWindows = factory.CreateGlassware();

            // Show what we've created...
            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleWindows.GlasswareParts);
            Console.Read();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: pitsanu/Lab_DesignPattern
        static void Main(string[] args)
        {
            string whatToMake = "van"; // or "van"
            AbstractVehicleFactory factory = null;

            // Create the correct 'factory'...
            if (whatToMake.Equals("car"))
            {
                factory = new CarFactory();
            }
            else
            {
                factory = new VanFactory();
            }

            // Create the vehicle parts, either a car or a van...
            IBody vehicleBody = factory.CreateBody();
            IChassis vehicleChassis = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            // See what we've created...
            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleGlassware.GlasswareParts);

            Console.Read();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            string whatToMake = "car";
            AbstractVehicleFactory factory = null;

            if (whatToMake.Equals("car"))
            {
                factory = new CarFactory();
            }
            else
            {
                factory = new VanFactory();
            }

            IBody      vehicleBody      = factory.CreateBody();
            IChassis   vehicleChassis   = factory.CreateChassis();
            IGlassware vehicleGlassware = factory.CreateGlassware();

            Console.WriteLine(vehicleBody.BodyParts);
            Console.WriteLine(vehicleChassis.ChassisParts);
            Console.WriteLine(vehicleGlassware.GlasswarePart);
            Console.ReadKey();
        }