Example #1
0
        public Client()
        {
            Factory = new T();

            _productA = Factory.CreateVegetables();
            _productB = Factory.CreateFruits();
        }
Example #2
0
 //UNIT TEST
 public void Testc()
 {
     IAbstractFactory factory  = new ConcreteFactory2();
     IProductA        productA = factory.CreateProductA();
     IProductB        productB = factory.CreateProductB();
     //。。。。。。。。。。。。
     //虽然客户端依赖抽象的IAbstractFactory,但是为了获得IAbstractFactory,需要new ConcreteFactory2(),逻辑上和具体的工厂类型耦合在一起,“依赖注入”非常适用于结局这个问题,比如可以把ConcreteFactory2写在配置文件里,通过读取配置文件动态构造IAbstractFactory。
 }
Example #3
0
 public Promotion(IProductA productA, IProductB productB,
                  IProductC productC, IProductD productD)
 {
     _productA = productA;
     _productB = productB;
     _productC = productC;
     _productD = productD;
 }
Example #4
0
        public void AbstractFactoryTest()
        {
            IAbstractFactory factory  = new ConcreteFactory1();
            IProductA        productA = factory.CreateProductA();
            IProductB        productB = factory.CreateProductB();

            Assert.AreEqual(typeof(ProductA1), productA.GetType());
            Assert.AreEqual(typeof(ProductB1), productB.GetType());
        }
Example #5
0
        public void Test()
        {
            IAbstractFactory factory  = new ConcreteFactory2();
            IProductA        productA = factory.CreateProducctA();
            IProductB        productB = factory.CreateProducctB();

            Assert.AreEqual <Type>(typeof(ProductA2Y), productA.GetType());
            Assert.AreEqual <Type>(typeof(ProductB2), productB.GetType());
        }
        public void Test()
        {
            IAbstractFactory factory  = AssemblyFactory();
            IProductA        productA = factory.Create <IProductA>();
            IProductB        productB = factory.Create <IProductB>();

            Assert.AreEqual <Type>(typeof(ProductA1), productA.GetType());
            Assert.AreEqual <Type>(typeof(ProductB1), productB.GetType());
        }
Example #7
0
        public void Test1()
        {
            IAbstractFactory factory  = AssemblyFactory();
            IProductA        productA = factory.Create <IProductA>();
            IProductB        productB = factory.Create <IProductB>();

            Assert.IsInstanceOf(typeof(ProductA1), productA);
            Assert.IsInstanceOf(typeof(ProductB1), productB);
        }
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="factory">Объект который реализует интерфейс IFactory</param>
 public Client(IFactory factory)
 {
     if (factory == null)
      {
     throw new ArgumentNullException();
      }
      a = factory.GetProductA();
      b = factory.GetProductB();
 }
Example #9
0
        public static void GetDependentInstance()
        {
            var container = Utilities.UnityConfig.Register();

            _promotion = container.Resolve <IPromotion>();
            _productA  = container.Resolve <IProductA>();
            _productB  = container.Resolve <IProductB>();
            _productC  = container.Resolve <IProductC>();
            _productD  = container.Resolve <IProductD>();
        }
Example #10
0
        public void ProduceTest()
        {
            IAbstractFactory factory  = (new Assembler()).Create <IAbstractFactory>();//通过依赖注入,从配置文件生成
            IProductA        product1 = factory.CreateProductA();

            Assert.AreEqual("A1", product1.Type);
            IProductB product2 = factory.CreateProductB();

            Assert.AreEqual("B1", product2.Name);
        }
Example #11
0
    static void Main()
    {
        IFactory  factory  = new ConcreteFactory1();
        IProductA productA = factory.CreateProductA();

        productA.ShowA();
        IProductB productB = factory.CreateProductB();

        productB.ShowB();
        Console.ReadKey();
    }
Example #12
0
        public void AbstractFactoryWithMapperTest()
        {
            IDictionary <Type, Type> dictionary = new Dictionary <Type, Type>();

            dictionary.Add(typeof(IProductA), typeof(ProductA1));
            dictionary.Add(typeof(IProductB), typeof(ProductB1));

            IAbstractFactoryWithMapper factory = new ConcreteFactory(dictionary);
            IProductA productA = factory.Create <IProductA>();
            IProductB productB = factory.Create <IProductB>();

            Assert.AreEqual(typeof(ProductA1), productA.GetType());
            Assert.AreEqual(typeof(ProductB1), productB.GetType());
        }
Example #13
0
        private static void Test()
        {
            _firstFactory  = new FirstFactory((string Text) => Console.WriteLine(Text));
            _secondFactory = new SecondFactory((string Text) => Console.WriteLine(Text));

            IProductA firstProductA  = _firstFactory.CreateA();
            IProductA secondProductA = _secondFactory.CreateA();

            IProductB firstProductB  = _firstFactory.CreateB();
            IProductB secondProductB = _secondFactory.CreateB();

            firstProductA.OperationA();
            firstProductB.OperationB();
            secondProductA.OperationA();
            secondProductB.OperationB();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Use Products from Factory 1");
            IAbstractFactory factory   = new ConcreteFactory1();
            IProductA        productA1 = factory.GetProductA();
            IProductB        productB1 = factory.GetProductB();

            productA1.MethodX(); productA1.MethodY();
            productB1.Method1(); productB1.Method2();

            Console.WriteLine("Use Products from Factory 2");
            factory = new ConcreteFactory2();
            IProductA productA2 = factory.GetProductA();
            IProductB productB2 = factory.GetProductB();

            productA2.MethodX(); productA2.MethodY();
            productB2.Method1(); productB2.Method2();

            Console.ReadLine();
        }
Example #15
0
        static void TestAbstractFabric()
        {
            Console.Write("Select category first or second:");
            int category = int.Parse(Console.ReadLine());
            IAbstractFactory factory;

            if (category == 1)
            {
                factory = new FactoryFirstClass();
            }
            else
            {
                factory = new FactorySecondClass();
            }
            IProductA productA = factory.CreateProductA();
            IProductB productB = factory.CreateProductB();

            Console.WriteLine(productA.OperationA());
            Console.WriteLine(productB.OperationB());
            Console.WriteLine(productB.OperationWithProductA(productA));
        }
Example #16
0
        public string AnotherUsefulFunctionB(IProductA collaborator)
        {
            var result = collaborator.UsefulFunctionA();

            return($"The result of the collaboration with the ({result})");
        }
Example #17
0
 public void Interact(IProductA productA)
 {
     // Product B interacts with Product A
 }
Example #18
0
 public void Init()
 {
     this.a = this.f.CreateProductA();
     this.b = this.f.CreateProductB();
 }
Example #19
0
        // Ürün B2 varyantı, yalnızca Ürün A2 varyantıyla doğru şekilde çalışabilir.
        // Bununla birlikte, ProductA'nın herhangi bir örneğini bir argüman olarak kabul eder.
        public string AnotherFunctionB(IProductA collaborator)
        {
            var result = collaborator.FunctionA();

            return($"The result of the B2 collaborating with the ({result})");
        }
 public string OperationWithProductA(IProductA product)
 {
     return($"{this.OperationB()} AND {product.OperationA()}");
 }
 public ClientCode(IAbstractFactory factory)
 {
     productA = factory.CreateProductA();
     productB = factory.CreateProductB();
 }
Example #22
0
 public void Test()
 {
     IAbstractFactoryGai factory  = (new Assembler()).AssembleyFactory();
     IProductA           productA = factory.Create <IProductA>();
     IProductB           productB = factory.Create <IProductB>();
 }
Example #23
0
 public Client(IFactory factory)
 {
     productA = factory.CreateProductA();
     productB = factory.CreateProductB();
 }
Example #24
0
 public Client(IAbstractfactory factory)
 {
     _iProductA = factory.createProductA();
     _iProductB = factory.createProductB();
 }
Example #25
0
 public void Interact(IProductA a)
 {
     Console.WriteLine(this.GetType().Name +
                       " interacts with " + a.GetType().Name);
 }