Strategy_Pattern

 namespace WindowsFormsApp

{

    public interface IEmployeeSal

    {

         float GetSalary(int basic,float dividend,float commission);

    }

}

namespace WindowsFormsApp

{

    public class HRDeptSalary : IEmployeeSal

    {

       // @Override 

        public float GetSalary(int basic, float dividend, float commission)

        {

            return basic + dividend+commission;

        }

    }

    public class SalesDept : IEmployeeSal

    {

        // @Override 

        public float GetSalary(int basic, float dividend, float commission)

        {

            return basic + dividend+commission;

        }

    }

    public class PurchaseDept : IEmployeeSal

    {

        // @Override 

        public float GetSalary(int basic, float dividend, float commission)

        {

            return basic + dividend;

        }

    }

}

namespace WindowsFormsApp

{

    public class EmployeeSalary

    {

        public string EmployeeName { get; set; }

        public int Basic { get; set; }


        private IEmployeeSal _iEmployeeSal;


        public EmployeeSalary(IEmployeeSal iEmployeeSal)

        {

            this._iEmployeeSal = iEmployeeSal;

        }


        public float CalculateSalry(int basic, float dividend, float commission)

        {

            return _iEmployeeSal.GetSalary( basic,  dividend,  commission);

        }

    }

}

private void button1_Click(object sender, EventArgs e)

        {

            //Use the EmployeeSalary to see change in behaviour when it changes its Strategy.

            EmployeeSalary objEmpSal = null;

            objEmpSal = new EmployeeSalary(new HRDeptSalary());


           textBox1.Text = objEmpSal.CalculateSalry(9000,500,50).ToString();

            objEmpSal = new EmployeeSalary(new PurchaseDept());


            textBox2.Text = objEmpSal.CalculateSalry(5000, 200, 20).ToString();


        }

Comments

Popular posts from this blog

Travel RESUME CV

Tablig