Beispiel #1
0
        private static void Main()
        {
            var worker = new Worker("Worker Ivan", 5);
            var worker2 = new Worker("Worker Kiko", 3);
            var supervisorA = new Supervisor("Supervisor Atanas", 6);
            var supervisorB = new Supervisor("Supervisor Branimir", 7);
            var supervisorC = new Supervisor("Supervisor Ceco", 8);

            // setup relationships
            supervisorA.AddSubordinate(worker);
            supervisorB.AddSubordinate(supervisorA);
            supervisorC.AddSubordinate(supervisorB);
            supervisorC.AddSubordinate(worker2);

            supervisorC.ShowHappiness();
        }
Beispiel #2
0
        public static void Main()
        {
            Worker     tom   = new Worker("Worker Tom", 0);
            Supervisor mary  = new Supervisor("Supervisor Mary", 50);
            Supervisor jerry = new Supervisor("Supervisor Jerry", 100);
            Supervisor bob   = new Supervisor("Supervisor Bob", 50);
            Worker     jimmy = new Worker("Worker Jimmy", 0);

            // set up the relationships
            mary.AddSubordinate(tom);   // Tom works for Mary
            jerry.AddSubordinate(mary); // Mary works for Jerry
            jerry.AddSubordinate(bob);  // Bob works for Jerry
            bob.AddSubordinate(jimmy);  // Jimmy works for Bob

            // Jerry shows his happiness and asks everyone else to do the same
            jerry.ShowHappiness();
        }
Beispiel #3
0
        public static void TestEmployeeHappiness()
        {
            Worker     wTom   = new Worker("Worker Tom", 5);
            Supervisor sMary  = new Supervisor("Supervisor Mary", 6);
            Supervisor sJerry = new Supervisor("Supervisor Jerry", 7);
            Supervisor sBob   = new Supervisor("Supervisor Bob", 9);
            Worker     wJimmy = new Worker("Worker Jimmy", 8);

            //Setup the relationship b/w worker and supervisor
            sMary.AddSubordinate(wTom);   // Worker Tom works for Mary
            sJerry.AddSubordinate(sMary); // Supervisor Mary works for Jerry
            sJerry.AddSubordinate(sBob);  // Supervisor Bob works for Jerrry
            sBob.AddSubordinate(wJimmy);  // Worker Jimmy works for Bob

            // Jerry shows his happiness and asked everyone else to do the same
            sJerry.ShowHappiness();
        }
Beispiel #4
0
        public static void Main()
        {
            Worker tom = new Worker("Worker Tom", 0);
            Supervisor mary = new Supervisor("Supervisor Mary", 50);
            Supervisor jerry = new Supervisor("Supervisor Jerry", 100);
            Supervisor bob = new Supervisor("Supervisor Bob", 50);
            Worker jimmy = new Worker("Worker Jimmy", 0);

            // set up the relationships
            mary.AddSubordinate(tom); // Tom works for Mary
            jerry.AddSubordinate(mary); // Mary works for Jerry
            jerry.AddSubordinate(bob); // Bob works for Jerry
            bob.AddSubordinate(jimmy); // Jimmy works for Bob

            // Jerry shows his happiness and asks everyone else to do the same
            jerry.ShowHappiness();
        }
Beispiel #5
0
        //LD_COMPOSITE_000
        public static void RunCompositeStructuralPattern()
        {
            Worker     a = new Worker("Worker Tom", 5);
            Supervisor b = new Supervisor("Supervisor Mary", 6);
            Supervisor c = new Supervisor("Supervisor Jerry", 7);
            Supervisor d = new Supervisor("Supervisor Bob", 9);
            Worker     e = new Worker("Worker Jimmy", 8);

            //set up the relationships
            b.AddSubordinate(a); //Tom works for Mary
            c.AddSubordinate(b); //Mary works for Jerry
            c.AddSubordinate(d); //Bob works for Jerry
            d.AddSubordinate(e); //Jimmy works for Bob

            //"Jerry" shows his happiness and asks "mary" and "bob" to do the same
            if (c is CompositeStructuralPattern.IEmployee)
            {
                (c as CompositeStructuralPattern.IEmployee).ShowHappiness();
            }
        }
Beispiel #6
0
        public void TestMethod11()
        {
            Worker     worker     = new Worker("Tom", 3);
            Supervisor supervisor = new Supervisor("Mary", 6);

            Assert.IsNotInstanceOfType(worker.GetType(), typeof(Supervisor));
            List <IEmployee> subordinate = new List <IEmployee>();

            subordinate.Add(worker);
            supervisor.AddSubordinate(worker);
            Assert.IsNotNull(subordinate[0]);
        }
    static void Main(string[] args)
    {
        Supervisor Jerry = new Supervisor("Jerry", 7);
        Supervisor Marry = new Supervisor("Mary", 6);
        Supervisor Bob = new Supervisor("Bob", 9);
        Worker Jimmy = new Worker("Jimmy", 8);
        Worker Tom = new Worker("Tom", 5);
        Worker Alice = new Worker("Alice", 6);

        // Set up the relationships
        Jerry.AddSubordinate(Marry);    // Mary works for Jerry
        Jerry.AddSubordinate(Bob);      // Bob works for Jerry
        Marry.AddSubordinate(Tom);      // Tom works for Marry
        Bob.AddSubordinate(Jimmy);      // Jimmy works for Bob
        Bob.AddSubordinate(Alice);      // Alice works for Bob

        // Jerry shows his happiness and asks everyone else to do the same
        if (Jerry is IEmployee)
            (Jerry as IEmployee).ShowHappiness();

        Console.ReadKey();
    }
    static void Main(string[] args)
    {
        Supervisor Jerry = new Supervisor("Jerry", 7);
        Supervisor Marry = new Supervisor("Mary", 6);
        Supervisor Bob   = new Supervisor("Bob", 9);
        Worker     Jimmy = new Worker("Jimmy", 8);
        Worker     Tom   = new Worker("Tom", 5);
        Worker     Alice = new Worker("Alice", 6);

        // Set up the relationships
        Jerry.AddSubordinate(Marry);    // Mary works for Jerry
        Jerry.AddSubordinate(Bob);      // Bob works for Jerry
        Marry.AddSubordinate(Tom);      // Tom works for Marry
        Bob.AddSubordinate(Jimmy);      // Jimmy works for Bob
        Bob.AddSubordinate(Alice);      // Alice works for Bob

        // Jerry shows his happiness and asks everyone else to do the same
        if (Jerry is IEmployee)
        {
            (Jerry as IEmployee).ShowHappiness();
        }

        Console.ReadKey();
    }
Beispiel #9
0
        public void TestMethod12()
        {
            Worker     worker     = new Worker("Tom", 3);
            Supervisor supervisor = new Supervisor("Mary", 6);

            Assert.IsNotInstanceOfType(worker.GetType(), typeof(Supervisor));
            List <IEmployee> subordinate = new List <IEmployee>();

            subordinate.Add(worker);
            supervisor.AddSubordinate(worker);
            Assert.IsNotNull(subordinate[0]);
            Assert.AreEqual(subordinate[0], worker);

            Worker     w = new Worker("Jimm", 7);
            Supervisor s = new Supervisor("Martin", 8);

            subordinate.Add(w);
            s.AddSubordinate(w);
            Assert.AreEqual(subordinate[1], w);
            Assert.IsNotNull(subordinate[1]);
        }
    static void Main(string[] args)
    {
        Worker a = new Worker("Worker Tom", 5);
        Supervisor b = new Supervisor("Supervisor Mary", 6);
        Supervisor c = new Supervisor("Supervisor Jerry", 7);
        Supervisor d = new Supervisor("Supervisor Bob", 9);
        Worker e = new Worker("Worker Jimmy", 8);

        //set up the relationships
        b.AddSubordinate(a); //Tom works for Mary
        c.AddSubordinate(b); //Mary works for Jerry
        c.AddSubordinate(d); //Bob works for Jerry
        d.AddSubordinate(e); //Jimmy works for Bob

        //Jerry shows his happiness and asks everyone else to do the same
        if (c is IEmployee)
        {
            (c as IEmployee).ShowHappiness();
        }
    }