Пример #1
0
        private void TestDynamicBinding(int val)
        {
            Person pers;

            //static bindning to Person (early binding)

            //Depending on the value of "choice", the variable pers will dynamically refer to
            //different type of object wihin the inheritance hierarchy (dynamic binding or late binding)
            switch ((val))
            {
            case 1:
                pers = new Chief();
                break;

            case 2:
                pers = new Salesman();
                break;

            case 3:
                pers = new Employee();
                break;

            default:
                pers = new Person();
                break;
            }
        }
Пример #2
0
        private void btnIsA_Click(object sender, EventArgs e)
        {
            Chief boss = new Chief();

            boss.FirstName = "Nanna";
            string strText = string.Format("Chief is a Person who has the first name: {0}. ", boss.FirstName);

            MessageBox.Show(strText, "Is - a relationship");
        }
Пример #3
0
        private void btnDynamicBin_Click(object sender, EventArgs e)
        {
            Person per1 = new Person();         //1
            Person per2 = new Employee();       //2

            per2 = new Chief();                 //3
            Salesman per3 = new Salesman();     //4

            TestaDnyanmiskBinding(2);
            TestaDnyanmiskBinding(3);
            TestaDnyanmiskBinding(4);
        }
Пример #4
0
        private void btnChief_Click(object sender, EventArgs e)
        {
            Chief departmentChief = new Chief();

            departmentChief.FirstName = "Nisse";
            //klassen Person
            departmentChief.SurName = "Lundström";
            //klassen Person
            departmentChief.Salary = 55000;
            //klassen Anställd
            departmentChief.Bonus = 120000;
            //klassen Chief
            MessageBox.Show("The boss earns: " + departmentChief.TotalIncome.ToString() + " a month!", "Test Program");
        }
Пример #5
0
        private void TestaDnyanmiskBinding(int choice)
        {
            Person pers;  //static binding to Person

            //Depending on the value of choice, pers will refer to
            //different types of object (within the hierarchy)
            switch (choice)
            {
            case 1:
                pers = new Chief();
                break;

            case 2:
                pers = new Salesman();
                break;

            case 3:
            default:
                pers = new Person();
                break;
            }
            MessageBox.Show(pers.ToString());
        }