예제 #1
0
        public static void Main(string[] args)
        {
            var genomeDatabase          = Generators.PrepareGenomes();
            var simpleDatabase          = Generators.PrepareSimpleDatabase(genomeDatabase);
            var excellDatabase          = Generators.PrepareExcellDatabase(genomeDatabase);
            var overcomplicatedDatabase = Generators.PrepareOvercomplicatedDatabase(genomeDatabase);
            var mediaOutlet             = new MediaOutlet(genomeDatabase);

            Console.WriteLine("------ Simple database ------\n");
            mediaOutlet.Publish(simpleDatabase);
            Console.WriteLine("\n------ Excel database ------\n");
            mediaOutlet.Publish(excellDatabase);
            Console.WriteLine("\n------ Overcomplicated database ------\n");
            mediaOutlet.Publish(overcomplicatedDatabase);

            Console.WriteLine("\n------ Decorators: filter Excel by DeathRate > 15 ------\n");
            Func <VirusData, bool> f = virus => virus.DeathRate > 15;
            IDecorator             filteredByDeathRate = new Filter(excellDatabase, f);

            mediaOutlet.Publish(filteredByDeathRate);


            Console.WriteLine("\n------ Decorators: increased death rate of each Excel virus by 10 and then filtered by DeathRate > 15 ------\n");
            Func <VirusData, VirusData> m  = virus => new VirusData(virus.VirusName, virus.DeathRate + 10, virus.InfectionRate, virus.Genomes);
            IDecorator MappingAndFiltering = new Mapping(excellDatabase, m);

            MappingAndFiltering = new Filter(MappingAndFiltering, f); // or we can declare two different IDecorator objects: IDecorator NotMappingAndFiltering = new Filter(MappingAndFiltering...);
            mediaOutlet.Publish(MappingAndFiltering);

/*            Console.WriteLine("\n------ Decorators: concat excel and overcomplicated databases ------");
 *          IDecorator concat = new Concat(excellDatabase, overcomplicatedDatabase);
 *          mediaOutlet.Publish(concat);*/

            Console.WriteLine();

            // testing animals
            var tester = new Tester();

            tester.Test();
        }