C# example- In the below example constants class is used for storing all the constants.
class Constants
{
public const int MinEmpId = 0;
}
//employee class
class Employee
{
public string Name { get; set; }
public int EmpId { get; }
public Employee()
{
}
//should not allow negative numbers
public bool SetEmpId(int iEmpId)
{
bool blnStatus = false;
if (iEmpId >= Constants.MinEmpId)
{
EmpId = iEmpId;
blnStatus = true;
}
return blnStatus;
}
}
Note: Follow the internationalization standards if your application has to support localization.
Rule: Do not hardcode values.
Rule: Follow internationalization standards if required.
No comments:
Post a Comment