Ejemplo n.º 1
0
 static Catalogue CreateCatalogue(AbstractFactory factory) {
     //Create a catalogue by adding factory products to it
     //Here we use the same construction process but allow the catalogue to contain a differet family of products
     Catalogue catalogue = factory.MakeCatalogue("Catalogue (Factory Made)");
     catalogue.AddProductA(factory.MakeProductA("1"));
     catalogue.AddProductA(factory.MakeProductA("2"));
     catalogue.AddProductA(factory.MakeProductA("3"));
     catalogue.AddProductB(factory.MakeProductB("1"));
     return catalogue;
 }
Ejemplo n.º 2
0
        //
        static void Main(string[] args) {
            //Create a catalogue with a known, single family of products 
            Catalogue catalogue = CreateCatalogue();
            Console.WriteLine(catalogue.ListProducts());

            //Create a catalogue with a family of default products
            AbstractFactory factory = new AbstractFactory();
            catalogue = CreateCatalogue(factory);
            Console.WriteLine(catalogue.ListProducts());

            //Create another catalogue with a new family of products
            AbstractFactory factory1 = new ConcreteFactory1();
            Catalogue catalogue1 = CreateCatalogue(factory1);
            Console.WriteLine(catalogue1.ListProducts());

            //Create another catalogue with another new family of products
            AbstractFactory factory2 = new ConcreteFactory2();
            Catalogue catalogue2 = CreateCatalogue(factory2);
            Console.WriteLine(catalogue2.ListProducts());
            Console.Read();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //Solid Desgin Principles
            //SingleResponsibilityPrinciple.run();
            //OpenClosedPrinciple.run();
            //LiskovSubstitutionPrinciple.run();
            //InterfaceSegregationPrinciple.run();
            //DependencyInversionPrinciple.run();

            //Builder Pattern
            //Builder.run();
            //FluentBuilderInheritanceRecursiveGenerics.run();
            //FacetedBuilder.run();

            //Factory Pattern
            //Factory.run();
            AbstractFactory.run();

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.ReadKey();
            }
        }
Ejemplo n.º 4
0
        private static void PrintAbstractFactory()
        {
            Console.WriteLine(@"----------------------------------------------------------------------");
            Console.WriteLine(@"---                   Examples of design patterns                  ---");
            Console.WriteLine(@"---                        Abstract factory                        ---");
            Console.WriteLine(@"----------------------------------------------------------------------");

            string factoryName     = PrintAbstractFactory_GetFactoryName(EnumDbProvider.SqlClient);
            var    providerFactory = DbProviderFactories.GetFactory(factoryName);
            var    authentication  = new Authentication();
            var    abstractFactory = new AbstractFactory(providerFactory, @"LOCALHOST\SQL2019", "SAMPLE", authentication, "DesignPatterns");
            var    query           = "SELECT * FROM [HUMAN] WHERE [ID] > @ID ORDER BY [ID]";

            Console.WriteLine($@"string {nameof(factoryName)} = {nameof(PrintAbstractFactory_GetFactoryName)}({nameof(EnumDbProvider)}.{factoryName});");
            Console.WriteLine($@"var {nameof(providerFactory)} = DbProviderFactories.GetFactory({nameof(factoryName)});");
            Console.WriteLine($@"var {nameof(authentication)} = new Authentication();");
            Console.WriteLine($@"var {nameof(abstractFactory)} = new {nameof(AbstractFactory)}(" +
                              $@"{nameof(providerFactory)}, ""{abstractFactory.DataSource}"", ""{abstractFactory.InitialCatalog}"", {nameof(authentication)});");

            Console.WriteLine($@"var query = ""{query}""");
            Console.WriteLine(@"----------------------------------------------------------------------");
            var records = abstractFactory.SelectData(query,
                                                     new Collection <(string, object)>()
            {
                ("ID", 10)
            },
                                                     new Collection <string>()
            {
                "ID", "FIRSTNAME", "LASTNAME", "SURNAME"
            });

            foreach (var record in records)
            {
                Console.WriteLine(string.Join("; ", record));
            }
        }
Ejemplo n.º 5
0
 public Client(AbstractFactory factory)
 {
     _abstractProductA = factory.CreateProductA();
     _abstractProductB = factory.CreateProductB();
 }
Ejemplo n.º 6
0
 public Client(AbstractFactory product)
 {
     productA = product.GetProductA();
     productB = product.GetProductB();
 }
 // Constructor
 public Client(AbstractFactory factory)
 {
     _abstractProductB = factory.CreateProductB();
     _abstractProductA = factory.CreateProductA();
 }