public void TestMethod1()
        {
            List <IFruit> fruitSalad = new List <IFruit>();
            Orange        orange     = new Orange();
            Banana        banana     = new Banana();

            fruitSalad.Add(orange);
            fruitSalad.Add(banana);

            foreach (IFruit fruit in fruitSalad)
            {
                fruit.Peel();
            }
        }
Esempio n. 2
0
        public void ColumnName()
        {
            var set = this.Database.Set <Orange>(this.Transaction);

            set.Clear();
            var data = new Orange()
            {
                Field1 = "1", Field2 = "2", Field3 = "3", Field4 = "3"
            };
            var id = set.AddOrUpdate(data).Id;

            Assert.AreEqual(data, set.Find(id));
            Assert.AreEqual(data.Field4, set.Find(id).Field4);
        }
Esempio n. 3
0
        public IHttpActionResult DeleteOrange(int id)
        {
            Orange orange = db.Oranges.Find(id);

            if (orange == null)
            {
                return(NotFound());
            }

            db.Oranges.Remove(orange);
            db.SaveChanges();

            return(Ok(orange));
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Apple  apple  = new Apple();
            Orange orange = new Orange();

            apple.GetColor("green");
            orange.GetColor("red");

            AppleAdapter  appleAdapter  = new AppleAdapter(orange);
            OrangeAdapter orangeAdapter = new OrangeAdapter(apple);

            appleAdapter.GetColor("blue");
            orangeAdapter.GetColor("yellow");
        }
Esempio n. 5
0
        // GET: OrangesMvc/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Orange orange = db.Oranges.Find(id);

            if (orange == null)
            {
                return(HttpNotFound());
            }
            return(View(orange));
        }
Esempio n. 6
0
        public void GetToKnow()
        {
            Apple apple = new Apple();

            apple.GetColor();
            apple = new Orange();
            apple.GetColor();

            // After
            Fruit appleAfter = new OrangeAfter();

            appleAfter.GetColor();
            appleAfter = new AppleAfter();
            appleAfter.GetColor();
        }
        public void Main()
        {
            IComparableThings <Fruit> fc = new FruitComparer();
            Apple  apple1 = new Apple();
            Apple  apple2 = new Apple();
            Orange orange = new Orange();

            bool b1 = fc.FirstIsBetter(apple1, orange);
            bool b2 = fc.FirstIsBetter(apple1, apple2);

            IComparableThings <Apple> ac = fc;
            bool b3 = ac.FirstIsBetter(apple1, apple2);
            // bool b4 = ac.FirstIsBetter(apple1, orange);

            IComparableThings <Fruit> fc1 = (IComparableThings <Fruit>)ac;
        }
        /// <summary>
        /// Oh no! We have to implement our own fruit salad.
        /// Create a class, and give it some AddX() methods for each fruit.
        /// </summary>
        public void SecondExercise()
        {
            var apple  = new Apple();
            var pear   = new Pear();
            var lime   = new Lime();
            var orange = new Orange();


            // Create the CustomFruitSaladImplementation
            var fruitSalad = new CustomFruitSaladImplementation();

            // Implement an AddX for each fruit type above and call it
            // It doesn't have to do anything
            // E.g. fruitSalad.AddApple(apple);
            // fruitSalad.AddPear(pear);
        }
Esempio n. 9
0
        /// <summary>
        /// Oh no! all the fruits are named the wrong names!
        /// Fix them, both in the constructor and the FruitSalad.AddX methods!
        /// </summary>
        public void FirstExercise()
        {
            var pear   = new Apple();
            var apple  = new Pear();
            var orange = new Lime();
            var lime   = new Orange();


            // Creat the CustomFruitSaladImplementation
            var fruitSalad = new FruitSalad();

            fruitSalad.AddApple(pear);
            fruitSalad.AddPear(apple);
            fruitSalad.AddLime(orange);
            fruitSalad.AddOrange(lime);
        }
    static void Main()
    {
        Apple obj1 = new Apple();

        obj1.Info();

        Banana obj = new Banana();

        obj.Info();

        Orange obj2 = new Orange();

        obj2.Info();

        Console.ReadLine();
    }
        static void Main(string[] args)
        {
            Apple  apple  = new Apple(0.6);
            Orange orange = new Orange(0.25);

            List <Fruit> liste = new List <Fruit>();

            liste.Add(apple);
            liste.Add(orange);
            liste.Add(orange);
            liste.Add(orange);
            ShoppingCart sc = new ShoppingCart(liste);

            Console.WriteLine(sc.total());
            Console.ReadKey();
        }
Esempio n. 12
0
        public void Chop(Mobile from)
        {
            if (from.InRange(this.GetWorldLocation(), 1))
            {
                if ((chopTimer == null) || (!chopTimer.Running))
                {
                    if ((TreeHelper.TreeOrdinance) && (from.AccessLevel == AccessLevel.Player))
                    {
                        if (from.Region is Regions.GuardedRegion)
                        {
                            from.CriminalAction(true);
                        }
                    }

                    chopTimer = new TreeHelper.ChopAction(from);

                    Point3D pnt = this.Location;
                    Map     map = this.Map;

                    from.Direction = from.GetDirectionTo(this);
                    chopTimer.Start();

                    double lumberValue = from.Skills[SkillName.Lumberjacking].Value / 100;
                    if ((lumberValue > .5) && (Utility.RandomDouble() <= lumberValue))
                    {
                        Orange fruit = new Orange((int)Utility.Random(13) + m_yield);
                        from.AddToBackpack(fruit);

                        int cnt  = Utility.Random((int)(lumberValue * 10) + 1);
                        Log logs = new Log(cnt);                           // Fruitwood Logs ??
                        from.AddToBackpack(logs);

                        FruitTreeStump i_stump = new FruitTreeStump(typeof(OrangeTree));
                        Timer          poof    = new StumpTimer(this, i_stump, from);
                        poof.Start();
                    }
                    else
                    {
                        from.SendLocalizedMessage(500495);                        // You hack at the tree for a while, but fail to produce any useable wood.
                    }
                }
            }
            else
            {
                from.SendLocalizedMessage(500446);                 // That is too far away.
            }
        }
Esempio n. 13
0
        private static int RotOranges(int[,] arr)
        {
            Queue <Orange>   queue         = new Queue <Orange>();
            HashSet <Orange> hsRotten      = new HashSet <Orange>();
            int  timeElapsed               = 0;
            bool anyOrangeRottenInUnitTime = false;

            foreach (Orange orange in GetRottenOranges(arr))
            {
                queue.Enqueue(orange);
            }

            queue.Enqueue(null); //Delimiter for current batch

            while (queue.Count > 0)
            {
                Orange current = queue.Dequeue();

                if (current != null)
                {
                    if (RotAdjacentOranges(current, arr, queue))
                    {
                        if (anyOrangeRottenInUnitTime != true)
                        {
                            anyOrangeRottenInUnitTime = true;
                        }
                    }
                }
                else
                {
                    if (queue.Count > 0)
                    {
                        queue.Enqueue(null);
                    }

                    if (anyOrangeRottenInUnitTime)
                    {
                        timeElapsed++;
                        anyOrangeRottenInUnitTime = false;
                    }
                }
            }

            return(IsEveryOrangeRotten(arr) ? timeElapsed : -1);
        }
Esempio n. 14
0
        private static List <Orange> GetRottenOranges(int[,] arr)
        {
            List <Orange> lstRotten = new List <Orange>();

            for (int r = 0; r <= arr.GetLength(0) - 1; r++)
            {
                for (int c = 0; c <= arr.GetLength(1) - 1; c++)
                {
                    if (arr[r, c] == 2)
                    {
                        Orange orange = new Orange(r, c, 2);
                        lstRotten.Add(orange);
                    }
                }
            }

            return(lstRotten);
        }
        static void Main(string[] args)
        {
            Apple a = new Apple(4.4M);
            Console.WriteLine(a.Price);
            Console.WriteLine(a);

            Apple b = new Apple(3);
            Console.WriteLine(b);

            Apple c = new Apple();
            Console.WriteLine(c);

            Orange o = new Orange(10.4m);
            Console.WriteLine(o);

            Orange p = new Orange();
            Console.WriteLine(p);
        }
Esempio n. 16
0
        public void InterfacesInCollections()
        {
            //arange
            var orange     = new Orange();
            var fruitSalad = new List <IFruit>
            {
                new Banana(),
                new Grape(),
                orange
            };

            foreach (var fruit in fruitSalad)
            {
                Console.WriteLine($"{fruit.Name} {fruit.Peel()}");
                Assert.IsInstanceOfType(fruit, typeof(IFruit));
            }
            Console.WriteLine(orange.Squeeze());
        }
Esempio n. 17
0
        public void Calculate_Promotion_Applied()
        {
            // Arrange
            var target = new OrangePromtion();
            var cart   = new Cart();
            var orange = new Orange {
                Quantity = 5
            };

            cart.Items.Add(orange);

            // Act
            target.Calculate(cart);

            // Assert
            Assert.Single <CartItem>(cart.Items, i => i.Description == "Promotion");
            Assert.Equal(-25M, cart.Items.First(i => i.Description == "Promotion").Price);
        }
Esempio n. 18
0
        public void Run()
        {
            List <IFruit> fruitSalad = new List <IFruit>();
            Banana        banana     = new Banana();
            Orange        orange     = new Orange(false);
            Grape         grape      = new Grape();
            Grape         otherGrape = new Grape();

            fruitSalad.Add(banana);
            fruitSalad.Add(orange);
            fruitSalad.Add(grape);
            fruitSalad.Add(otherGrape);

            foreach (IFruit fruit in fruitSalad)
            {
                _console.WriteLine($"This is a {fruit.Name}");
                _console.WriteLine(fruit.Peel());
            }
        }
Esempio n. 19
0
        public void InterfacesInCollections()
        {
            var orangeObject = new Orange();
            var fruitSalad   = new List <IFruit>
            {
                new Banana(),
                new Grape(),
                new Orange(true),
                orangeObject
            };

            foreach (var oneFruit in fruitSalad)
            {
                Console.WriteLine(oneFruit.Name);
                Console.WriteLine(oneFruit.Peel());
                Assert.IsInstanceOfType(oneFruit, typeof(IFruit));
                Assert.IsInstanceOfType(orangeObject, typeof(Orange));
            }
        }
Esempio n. 20
0
        public void EatFood()
        {
            // We've coupled ourselves to the Console implementation
            Console.WriteLine("I'm hungry, what do we have to eat? ");
            string food = Console.ReadLine();

            // We are newing classes here too!
            if (food == "orange")
            {
                var orange = new Orange();
                orange.Peel();
                orange.Eat();
            }
            else if (food == "steak")
            {
                var steak = new Steak();
                steak.Cook();
                steak.Eat();
            }
            //
            // Adding more types of foods means we need to add more conditional blocks and we need to know how to eat the pie too
            // This class can get complex and large fast if we don't invert the control of creating the food
            // We will also need to abstract how to eat food so we can invert the control of how to eat food to each food type
            //
            // Now what if we need a stomach class to know all of these types of food too?
            // For every type of food, we would need to now touch two classes as well as more code branches which grows the complexity further
            // Coding to abstractions (interfaces) and inverting control will make these classes easier to manage and evolve
            //
            else if (food == "apple pie")
            {
                var pie = new ApplePie();
                pie.Warm();
                pie.Eat();
            }
            else
            {
                Console.WriteLine("I don't know how to eat " + food);
                return;
            }

            Console.WriteLine("Thanks, that was good");
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            Animal[] animals = new Animal[2];
            animals[0] = new Tiger();
            animals[1] = new Chicken();

            foreach (Animal i in animals)
            {
                i.makeSound();
            }

            Fruit[] fruits = new Fruit[2];
            fruits[0] = new Apple();
            fruits[1] = new Orange();

            foreach (Fruit i in fruits)
            {
                i.howToEat();
            }
        }
Esempio n. 22
0
        public static void Main(string[] args)
        {
            // All of our classes are newed here
            var   human = new Human();
            IFood food;

            while (true)
            {
                // We have decoupled the human class from Console
                // Now a human can work with vary input types much easier
                Console.WriteLine("I'm hungry, what do we have to eat? ");
                string input = Console.ReadLine()?.ToLower();

                // We can further abstract this logic (and getting the input too) further to allow for flexibility
                // DI frameworks will help to select the proper class
                if (input == "orange")
                {
                    // although we new this, the implementation makes this act like a singleton
                    food = new Orange();
                }
                else if (input == "steak")
                {
                    food = new Steak();
                }
                else if (input == "apple")
                {
                    food = new Apple();
                }
                else
                {
                    throw new Exception("I don't know how to eat " + input);
                }

                // The human class is no longer controlling the food it should eat, it is being handed food that it then eats
                // We can extend this idea to a potential stomach class if we need one
                human.EatFood(food);

                Console.WriteLine("Thanks, that was good");
            }
        }
Esempio n. 23
0
        private void timer1_Tick(object sender, EventArgs e)                    // таймер
        {
            ND.Infection(Chance, N, M, Iter);
            ND.Kol_vo(out Green, out Orange, out Red);
            ND.Regen(Iter);

            label9.Text  = Green.ToString();
            label11.Text = Orange.ToString();
            label13.Text = Red.ToString();

            newForm.pictureBox2.Image = DrawGraph(Green, Orange, Red, TMP);
            newForm.label_vsego.Text  = (N * M).ToString();
            newForm.label_g.Text      = Green.ToString();
            newForm.label_O.Text      = Orange.ToString();
            newForm.label_R.Text      = Red.ToString();
            if (N * M == Green)
            {
                Form3 f3 = new Form3();
                Flag_Start = true;
                f3.Show();
                timer1.Enabled = false;

                button2.Text = "Старт";
            }

            if (ClickLogick == 3)
            {
                ND.Info(p.X, p.Y, Iter, out X, out Y, out status, out IterToReg, out IterToImm);
                OU.label8.Text = X.ToString();
                OU.label9.Text = Y.ToString();
                OU.label2.Text = status;
                OU.label4.Text = IterToReg.ToString();
                OU.label6.Text = IterToImm.ToString();
            }

            Iter_from_start++;
            label16.Text = Iter_from_start.ToString();

            pictureBox1.Image = ND.RefreshBox(Box);
        }
Esempio n. 24
0
    static void Main(string[] args)
    {
        Animal[] animals = new Animal[2];
        animals[0] = new Tiger();
        animals[1] = new Chicken();
        Fruit[] fruits = new Fruit[2];
        fruits[0] = new Orange();
        fruits[1] = new Apple();
        foreach (Fruit fruit in fruits)
        {
            Console.WriteLine(fruit.HowToEat());
        }

        foreach (Animal animal in animals)
        {
            Console.WriteLine(animal.MakeSound());
            if (animal is Chicken)
            {
                Edible edibler = (Chicken)animal;
                Console.WriteLine(edibler.HowToEat());
            }
        }
    }
Esempio n. 25
0
        public void FruitTest()
        {
            Banana banana = new Banana();
            Orange orange = new Orange(true);
            Grape  grape  = new Grape();
            Tomato tomato = new Tomato();

            orange.Peel();
            Mandarin      mandarin = new Mandarin(true);
            List <IFruit> basket   = new List <IFruit>();

            basket.Add(banana);
            basket.Add(grape);
            basket.Add(orange);
            basket.Add(mandarin);
            basket.Add(tomato);

            foreach (IFruit fruit in basket)
            {
                Console.WriteLine(fruit.Name != "grape" || fruit.Name != "tomato"
                                                ? fruit.Peel()
                                                : $"Can't peel {fruit.Name}");;
            }
        }
        static void Main()
        {
            // Allowed in C# 4.0
            ICompareThings <Fruit> fc = new FruitComparer();

            Apple apple1 = new Apple();

            Apple  apple2 = new Apple();
            Orange orange = new Orange();

            // A fruit comparer can compare apples and oranges:

            bool b1 = fc.FirstIsBetter(apple1, orange);
            // or apples and apples:

            bool b2 = fc.FirstIsBetter(apple1, apple2);
            // This is legal because the interface is
            // contravariant.
            ICompareThings <Apple> ac = fc;
            // This is really a fruit comparer, so it can
            // still compare two apples

            bool b3 = ac.FirstIsBetter(apple1, apple2);
        }
 public AppleAdapter(Orange orange) => this.orange = orange;
        public List<Fruit> WaveOne()
        {
            List<Fruit> Fruit = new List<Fruit>();
            int NumOfFruitDrop = 5;
            int FType = 0;
            int XPos = 0;
            int Ypos = 0;
            float TimeDrop = 0f;

            for (int x = 0; x < NumOfFruitDrop; ++x)
            {
                FType = FruitType();
                XPos = XPositionGenerator();
                Ypos = YPositionGenerator();
                TimeDrop = TimeGenerator(WaveLengthOne);

                switch (FType)
                {
                    case 0:
                        Apple apple = new Apple(pickApple, new Vector2(XPos, Ypos), new Rectangle(0, 0, 0, 0), ScreenWidth, ScreenHeight, TimeDrop);
                        Fruit.Add(apple);
                        break;
                    case 1:
                        Banana banana = new Banana(pickBanna, new Vector2(XPos, Ypos), new Rectangle(0, 0, 0, 0), ScreenWidth, ScreenHeight, TimeDrop);
                        Fruit.Add(banana);
                        break;
                    case 2:
                        Orange orange = new Orange(pickOrange, new Vector2(XPos, Ypos), new Rectangle(0, 0, 0, 0), ScreenWidth, ScreenHeight, TimeDrop);
                        Fruit.Add(orange);
                        break;
                    case 3:
                        Rotten_Apple Rottenapple = new Rotten_Apple(dumpApple, new Vector2(XPos, 0), new Rectangle(0, 0, 0, 0), ScreenWidth, ScreenHeight, TimeDrop);
                        Fruit.Add(Rottenapple);
                        break;
                    case 4:
                        Rotten_Banana Rottenbanana = new Rotten_Banana(dumpBanna, new Vector2(XPos, 0), new Rectangle(0, 0, 0, 0), ScreenWidth, ScreenHeight, TimeDrop);
                        Fruit.Add(Rottenbanana);
                        break;
                    case 5:
                        Rotten_Orange Rottenorange = new Rotten_Orange(dumpOrange, new Vector2(XPos, 0), new Rectangle(0, 0, 0, 0), ScreenWidth, ScreenHeight, TimeDrop);
                        Fruit.Add(Rottenorange);
                        break;
                    default:
                        break;
                }

            }

            return Fruit;
        }
 static SomeClass()
 {
     a  = new Apple();
     _b = new Orange(a.getDna());
     c  = new Apple(_b.getDna());
 }
 public SomeClass()
 {
     b  = _b;
     _b = null;
 }
 //果农为桔子树浇水
 public override void VisitOrange(Orange myClassB)
 {
     myClassB.PlantOrange();
     Console.WriteLine("果农为桔子树浇水");
 }
 //果农为桔子树松土
 public override void VisitOrange(Orange orange)
 {
     orange.PlantOrange();
     Console.WriteLine("果农为桔子树松土");
 }
 public abstract void VisitOrange(Orange orange);
Esempio n. 34
0
        static void Main(string[] args)
        {
            //The Dependency Inversion Principle (DIP) states that high-level modules/classes should not depend on low-level modules/classes.
            //Both should depend upon abstractions. Secondly, abstractions should not depend upon details. Details should depend upon abstractions.
            //dependency inversion principle
            var employee = new EmployeeBusinessLogic();

            Console.WriteLine(JsonSerializer.Serialize(employee.GetEmployeeDetails(1)));

            //dependency inversion principle

            //liskov substitution principle : This principle states that, if S is a subtype of T, then objects of type T should be replaced with the objects of type S.
            // yerine koyma

            Apple apple = new Orange();

            Console.WriteLine(apple.GetColor());

            //after

            Fruit fruit = new Avocado();

            Console.WriteLine(fruit.GetColor());
            fruit = new Banana();
            Console.WriteLine(fruit.GetColor());

            //liskov substitution principle

            //open close principle

            var invoice = new Invoice();

            Console.WriteLine(invoice.GetInvoiceDiscount(1000, InvoiceType.FinalInvoice));
            Console.WriteLine(invoice.GetInvoiceDiscount(1000, InvoiceType.ProposedInvoice));

            //after

            InvoiceOCP fInvoice = new FinalInvoice();
            InvoiceOCP pInvoice = new ProposedInvoice();
            InvoiceOCP rInvoice = new RecurringInvoice();

            Console.WriteLine(fInvoice.GetInvoiceDiscount(100));
            Console.WriteLine(pInvoice.GetInvoiceDiscount(100));
            Console.WriteLine(rInvoice.GetInvoiceDiscount(100));

            //open close principle


            Console.Read();


            /*
             *
             * Single Responsibility : Sınıflarımızın iyi tanımlanmış tek bir sorumluluğu olmalı.
             * Open/Closed : Sınıflarımız değişikliğe kapalı ancak yeni davranışların eklenmesine açık olmalı.
             * Liskov Substitution(yerine koyma) : Kodumuzda herhangi bir değişiklik yapmaya gerek kalmadan türetilmiş sınıfları (sub class) türedikleri ata sınıfın (base class) yerine kullanabilmeliyiz.
             * Interface Segregation : Genel kullanım amaçlı tek bir kontrat yerine daha özelleşmiş birden çok kontrat oluşturmayı tercih etmeliyiz.
             * Dependency Inversion : Katmanlı mimarilerde üst seviye modüller alt seviyedeki modüllere doğruda bağımlı olmamalıdır.
             *
             */

            // https://dotnettutorials.net/lesson/dependency-inversion-principle/
        }
        public override void OnDoubleClick(Mobile from)
        {
            if (m_sower == null || m_sower.Deleted)
            {
                m_sower = from;
            }
            if (from != m_sower)
            {
                from.SendMessage("You do not own this plant !!!"); return;
            }

            if (from.Mounted && !CropHelper.CanWorkMounted)
            {
                from.SendMessage("You cannot harvest a crop while mounted."); return;
            }
            if (DateTime.UtcNow > lastpicked.AddSeconds(3))
            {
                lastpicked = DateTime.UtcNow;
                int cookValue = (int)from.Skills[SkillName.Cooking].Value / 20;
                if (cookValue == 0)
                {
                    from.SendMessage("You have no idea how to harvest this crop."); return;
                }
                if (from.InRange(this.GetWorldLocation(), 1))
                {
                    if (m_yield < 1)
                    {
                        from.SendMessage("There is nothing here to harvest.");
                    }
                    else
                    {
                        from.Direction = from.GetDirectionTo(this);
                        from.Animate(from.Mounted ? 29:32, 5, 1, true, false, 0);
                        m_lastvisit = DateTime.UtcNow;
                        if (cookValue > m_yield)
                        {
                            cookValue = m_yield + 1;
                        }
                        int pick = Utility.RandomMinMax(cookValue - 4, cookValue);
                        if (pick < 0)
                        {
                            pick = 0;
                        }
                        if (pick == 0)
                        {
                            from.SendMessage("You do not manage to harvest any crops."); return;
                        }
                        m_yield -= pick;
                        from.SendMessage("You harvest {0} crop{1}!", pick, (pick == 1 ? "" : "s"));
                        if (m_yield < 1)
                        {
                            ((Item)this).ItemID = pickedGraphic;
                        }
                        Orange crop = new Orange(pick);
                        from.AddToBackpack(crop);
                        if (!regrowTimer.Running)
                        {
                            regrowTimer.Start();
                        }
                    }
                }
                else
                {
                    from.SendMessage("You are too far away to harvest anything.");
                }
            }
        }