Пример #1
0
        static void Main(string[] args)
        {
            Products.Products.Product1 p1 = new Products.Products.Product1();
            Products.Products.Product2 p2 = new Products.Products.Product2();
            Products.Products.Product3 p3 = new Products.Products.Product3();
            FactoryPattern.Products.Products.CompareProducts compareProducts = new Products.Products.CompareProducts();
            AbstractProduct.AbstractProduct.Item item = compareProducts.ComparePrice(p1,p2,p3);
            Console.WriteLine("Where Name = {0}, Price = {1} ", item.Name, item.Price);

            for (int i = 0; i <= 3; i++)
            {
                AbstractProduct.AbstractProduct.Item position = FactoryPattern.Factory.Factory.GetProductByID(i);
                Console.WriteLine("Where id = {0}, position = {1} ", i, position.Name, position.Price);
                //Console.WriteLine("Where id = {0}, position = {1} ", i, position.Name = "ProductA"+i, position.Price = 7.99M * i);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Products.Products.Product1 p1 = new Products.Products.Product1();
            Products.Products.Product2 p2 = new Products.Products.Product2();
            Products.Products.Product3 p3 = new Products.Products.Product3();
            FactoryPattern.Products.Products.CompareProducts compareProducts = new Products.Products.CompareProducts();
            AbstractProduct.AbstractProduct.Item             item            = compareProducts.ComparePrice(p1, p2, p3);
            Console.WriteLine("Where Name = {0}, Price = {1} ", item.Name, item.Price);

            for (int i = 0; i <= 3; i++)
            {
                AbstractProduct.AbstractProduct.Item position = FactoryPattern.Factory.Factory.GetProductByID(i);
                Console.WriteLine("Where id = {0}, position = {1} ", i, position.Name, position.Price);
                //Console.WriteLine("Where id = {0}, position = {1} ", i, position.Name = "ProductA"+i, position.Price = 7.99M * i);
            }
        }
Пример #3
0
 public override AbstractProduct.AbstractProduct.Item ComparePrice(Products.Product1 p1, Products.Product2 p2, Products.Product3 p3)
 {
     if (p1.Price <= p2.Price)
     {
         if (p3.Price <= p2.Price)
         {
             return(new Products.Product2());
         }
         else
         {
             return(new Products.Product3());
         }
     }
     else
     if (p1.Price <= p3.Price)
     {
         return(new Products.Product3());
     }
     else
     {
         return(new Products.Product1());
     }
 }