Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var flyweightFactory = new CarFactory();

            flyweightFactory.BuildVehicle("Honda");
            flyweightFactory.BuildVehicle("Toyota");

            flyweightFactory.GetAllCars();

            flyweightFactory.BuildVehicle("Subaru");
            flyweightFactory.BuildVehicle("Subaru");

            flyweightFactory.BuildVehicle("Ford");

            flyweightFactory.GetAllCars();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //you might read car model data from database
            CarFactory.AddCarModel("Audi Q3", new CarModel()
            {
                Brand = "Audi",
                Price = "$50,000",
            });
            CarFactory.AddCarModel("Audi A3", new CarModel()
            {
                Brand = "Audi",
                Price = "$40,000",
            });

            Car car1 = CarFactory.CreateCar("Audi A3");

            car1.Owner = "Ackerley";
            car1.Color = "Black";
            Car car2 = CarFactory.CreateCar("Audi A3");

            car2.Owner = "Maaravi";
            car2.Color = "Orange";
            Car car3 = CarFactory.CreateCar("Audi Q3");

            car3.Owner = "Maaravi";
            car3.Color = "Blue";
            Console.WriteLine("car1");
            Console.WriteLine(car1.ToString());
            Console.WriteLine();
            Console.WriteLine("car2");
            Console.WriteLine(car2.ToString());
            Console.WriteLine();
            Console.WriteLine("car3");
            Console.WriteLine(car3.ToString());
            Console.WriteLine();
            Console.WriteLine(car1.Model == car2.Model);
            Console.WriteLine(car1.Model == car3.Model);
        }