Beispiel #1
0
        static void Main(string[] args)
        {
            double TotalCost(IFruits[] Fru)
            {
                double totpri = 0.0;

                for (int i = 0; i < Fru.Length; i++)
                {
                    totpri += Fru[i].price;
                }
                return(totpri);
            }

            Apple  App1 = new Apple();
            Orange Ora  = new Orange();
            Apple  App2 = new Apple();
            Apple  App3 = new Apple();

            IFruits[] checkout = new IFruits[4];
            checkout[0] = App1;
            checkout[1] = Ora;
            checkout[2] = App2;
            checkout[3] = App3;

            Console.WriteLine(TotalCost(checkout));
            Console.ReadLine();
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            //simply fabric
            Console.WriteLine("Simply Fabric:");
            Console.WriteLine(Environment.NewLine);

            FruitsFactory fruitsfactory = new FruitsFactory();
            IFruits       orange        = fruitsfactory.CreateFruitInstance("orange");
            IFruits       apple         = fruitsfactory.CreateFruitInstance("apple");
            IFruits       plum          = fruitsfactory.CreateFruitInstance("plum");

            Console.WriteLine("Fruits:");
            Console.WriteLine(orange.DisplayType());
            Console.WriteLine(apple.DisplayType());
            Console.WriteLine(plum.DisplayType());
            Console.WriteLine(Environment.NewLine);

            //method fabric
            Console.WriteLine("Method Fabric:");
            Console.WriteLine(Environment.NewLine);

            VegetablesFactory karotFactory = new KarotFactory();
            IVegetables       karot        = karotFactory.BuildVegetables();

            VegetablesFactory potatoFactory = new PotatoFactory();
            IVegetables       potato        = potatoFactory.BuildVegetables();

            VegetablesFactory cucumberFactory = new CucumberFactory();
            IVegetables       cucumber        = cucumberFactory.BuildVegetables();

            Console.WriteLine("Vegetables:");
            Console.WriteLine(karot.DisplayVegetable());
            Console.WriteLine(potato.DisplayVegetable());
            Console.WriteLine(cucumber.DisplayVegetable());
            Console.WriteLine(Environment.NewLine);

            //abstract fabric
            Console.WriteLine("Abstract Fabric:");
            Console.WriteLine(Environment.NewLine);

            AuditConstruction auditConstruction;

            auditConstruction = new AuditConstruction(new InternalAuditFactory());
            auditConstruction.MakeAudit();

            auditConstruction = new AuditConstruction(new ExternalAuditFactory());
            auditConstruction.MakeAudit();

            Console.ReadKey();
        }
Beispiel #3
0
        private void FruitAdd(Func <IFruits> fruit)
        {
            IFruits      tmpfruit = fruit();
            ILocalizable tmpFruit;


            do
            {
                Point tmp = new Point(myRand.Next(15, gameBoard.Width - 15), myRand.Next(15, gameBoard.Height - 15));
                tmpfruit.SetLocation(tmp);
                tmpFruit = tmpfruit as ILocalizable;
            }while (CheckColision(tmpFruit));

            fruitsList.Add(tmpfruit);
        }
Beispiel #4
0
        public IFruits GetFruits(string fruitName)
        {
            Dictionary <string, IFruits> availableFruits = new Dictionary <string, IFruits>()
            {
                { "Mango", new Mango() },
                { "Orange", new Orange() }
            };
            IFruits fruit = availableFruits[fruitName];

            if (fruit == null)
            {
                throw new InvalidOperationException("Fruit is not avilable!");
            }
            return(fruit);
        }