Ananth Ananth - 4 years ago 92
C# Question

Interview question on Class design

Recently I Attended an interview. This question was asked.

This is the scenario.

We have two type of employees. Regular and contract employee.
Regular employees will be paid on a fixed basis at the end of the month.
Contract employees will be paid weekly based on the number of hours they worked.

Managers will be assigned to these employees for supervision.
A manager may have regular and contract employees under him.

This application will calculate the payroll for these employees.

They asked me to come up with the class design for this situation.

What answer is the interviewer expecting from me?.
Pointers in this direction will be highly appreciated.

Answer Source

following may be one of the design

design 1.

public class Employee
{
   public bool isContractEmployee
      { get; set;}

   public abstract float CalCulatePayroll();   
}


public class FullTimeEmp : Employee
{
   public override float CalCulatePayroll()
   {
   }
}

public class ContractEmp : Employee
{
  public int NoofHR
      {get; set;}

  public override float CalCulatePayroll()
   {
       sal = nohr*money;
   }
}

design 2.

public class employee
{
  public bool isContractEmployee
  { get; set;}

  public int NoofHR
  {get; set;}


  public  float CalCulatePayroll()
  {
    if(this.isContractEmployee)
    {
      //calculate sal on based hr
    }
    else
    {
      //calculate regurlare sal
    }
  }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download