Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Last active December 20, 2015 11:49
Show Gist options
  • Save yemrekeskin/6126131 to your computer and use it in GitHub Desktop.
Save yemrekeskin/6126131 to your computer and use it in GitHub Desktop.
Strategy Design Pattern implementation - Salary and Permit Scenarios
public interface ISalaryCalc
{
decimal GetSalary();
}
public class EngineerSalaryCalc
:ISalaryCalc
{
public decimal GetSalary()
{
Console.WriteLine("Engineer -> Salary");
return 2500;
}
}
public class ManagerSalaryCalc
: ISalaryCalc
{
public decimal GetSalary()
{
Console.WriteLine("Manager -> Salary");
return 5000;
}
}
public class TecnicianSalaryCalc
: ISalaryCalc
{
public decimal GetSalary()
{
Console.WriteLine("Tecnician -> Salary");
return 1000;
}
}
public interface IPermitCalc
{
short GetPermitCount();
}
public class ManagerPermitCalc
: IPermitCalc
{
public short GetPermitCount()
{
Console.WriteLine("Manager -> PermitCount");
return 30;
}
}
public class TecnicianPermitCalc
: IPermitCalc
{
public short GetPermitCount()
{
Console.WriteLine("Tecnician -> PermitCount");
return 15;
}
}
public class EngineerPermitCalc
: IPermitCalc
{
public short GetPermitCount()
{
Console.WriteLine("Engineer -> PermitCount");
return 25;
}
}
public class Staff
{
private ISalaryCalc _salaryCalc;
private IPermitCalc _permitCalc;
public Staff(ISalaryCalc salaryCalc,IPermitCalc permitCalc)
{
this._permitCalc = permitCalc;
this._salaryCalc = salaryCalc;
}
public decimal GetSalary()
{
return this._salaryCalc.GetSalary();
}
public short GetPermitCount()
{
return this._permitCalc.GetPermitCount();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment