//Structural
        public static void AbstractFactoryStructural()
        {
            // Abstract factory #1

            AbstractFactory factory1 = new ConcreteFactory1();

            Log.WriteLine("{0} has Created", factory1.GetType().Name);


            var client1 = new Client(factory1);

            Log.WriteLine("{0} has Created", client1.GetType().Name);
            Log.WriteLine("Client Create AbstractProductA and AbstractProductB");
            Log.WriteLine("Client Run");
            client1.Run();

            Log.AddSeparator(5);
            // Abstract factory #2
            AbstractFactory factory2 = new ConcreteFactory2();

            Log.WriteLine("{0} has Created", factory2.GetType().Name);
            var client2 = new Client(factory2);

            Log.WriteLine("{0} has Created", client2.GetType().Name);
            Log.WriteLine("Client Create AbstractProductA and AbstractProductB");
            Log.WriteLine("Client Run");
            client2.Run();
        }
Esempio n. 2
0
        public static void TestAbstractFactory()
        {
            AbstractFactory factory1 = new ConcreteFactory1();
            var             client1  = new Client(factory1);

            AbstractFactory factory2 = new ConcreteFactory2();
            var             client2  = new Client(factory2);

            Assert.AreNotEqual(factory1.GetType().Name, factory2.GetType().Name);
            Assert.AreSame(factory1.GetType().BaseType, factory2.GetType().BaseType);

            Assert.AreSame(client1.GetType(), client2.GetType());

            StringAssert.AreEqualIgnoringCase("ProductB1 interacts with ProductA1", client1.Run(true));
            StringAssert.AreEqualIgnoringCase("ProductB2 interacts with ProductA2", client2.Run(true));
        }