You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Flyweight.Flyweights;
|
|
|
|
|
using Flyweight.Objects;
|
|
|
|
|
|
|
|
|
|
namespace Flyweight
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
AddCarToPoliceDatabase(factory, new Car
|
|
|
|
|
{
|
|
|
|
|
Number = "CL234IR",
|
|
|
|
|
Owner = "James Doe",
|
|
|
|
|
Company = "BMW",
|
|
|
|
|
Model = "M5",
|
|
|
|
|
Color = "red"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
AddCarToPoliceDatabase(factory, new Car
|
|
|
|
|
{
|
|
|
|
|
Number = "CL234IR",
|
|
|
|
|
Owner = "James Doe",
|
|
|
|
|
Company = "BMW",
|
|
|
|
|
Model = "X1",
|
|
|
|
|
Color = "red"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
factory.ListFlyweights();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddCarToPoliceDatabase(FlyweightFactory factory, Car car)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Client: Adding a car to database.");
|
|
|
|
|
var flyweight = factory.GetFlyweight(new Car
|
|
|
|
|
{
|
|
|
|
|
Color = car.Color,
|
|
|
|
|
Model = car.Model,
|
|
|
|
|
Company = car.Company,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
flyweight.Operation(car);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|