Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // The client code usually creates a bunch of pre-populated
            // flyweights in the initialization stage of the application.
            var factory = new FlyweightFactory(
                new Car {
                Company = "Chevrolet", Model = "Camaro2018", Color = "pink"
            },
                new Car {
                Company = "Mercedes Benz", Model = "C300", Color = "black"
            },
                new Car {
                Company = "Mercedes Benz", Model = "C500", Color = "red"
            },
                new Car {
                Company = "BMW", Model = "M5", Color = "red"
            },
                new Car {
                Company = "BMW", Model = "X6", Color = "white"
            }
                );

            factory.listFlyweights();

            addCarToPoliceDatabase(factory, new Car
            {
                Number  = "CL234IR",
                Owner   = "James Doe",
                Company = "BMW",
                Model   = "M5",
                Color   = "red"
            });

            addCarToPoliceDatabase(factory, new Car
            {
                Number  = "CL234IR",
                Owner   = "James Doe",
                Company = "BMW",
                Model   = "X1",
                Color   = "red"
            });

            factory.listFlyweights();
        }