コード例 #1
0
        private static void WithoutUsingFactoryPattern(int EmpType)
        {
            //Code without using Factory Design Pattern

            if (EmpType == 1)
            {
                PermanantEmployee emp = new PermanantEmployee();
                emp.Pay   = 10;
                emp.Bonus = 8;
            }
            else if (EmpType == 2)
            {
                TemporaryEmployee emp = new TemporaryEmployee();
                emp.Pay   = 12;
                emp.Bonus = 6;
            }
            else if (EmpType == 3)
            {
                ContractualEmployee emp = new ContractualEmployee();
                emp.Pay   = 8;
                emp.Bonus = 4;
            }

            //perform operation on emp object.
        }
コード例 #2
0
        public override IEmployee GetEmployee(string name, string dept, double salary, EmployeeType type)
        {
            IEmployee newEmployee = null;

            switch (type)
            {
            case EmployeeType.Permanant:
                newEmployee = new PermanantEmployee(name, dept, salary);
                break;

            case EmployeeType.Contract:
                newEmployee = new ContractEmployee(name, dept, salary);
                break;

            case EmployeeType.Intern:
                newEmployee = new InternEmployee(name, dept, salary);
                break;

            default:
                break;
            }
            return(newEmployee);
        }