Question Heading seems to be little confusing, But I will Try to clear my question here.
using System;
using System.Collections.Generic;
usi
Use dependency injection. Create a BonusCalculator
class:
public abstract class BonusCalculator
{
public abstract decimal CalculateBonus(Employee e)
}
In your base class:
private BonusCalculator Calculator { get; set; }
public void GiveBonus()
{
Bonus = Calculator.CalculateBonus(this)
}
In your implementation's constructor:
public SomeKindOfEmployee()
{
Calculator = new SomeKindOfEmployeeBonusCalculator();
}
Someone implementing a Person
subclass now has to explicitly provide it with an instance of a BonusCalculator
(or get a NullReferenceException
in the GiveBonus
method).
As an added, er, bonus, this approach allows different subclasses of Person
to share a bonus-calculation method if that's appropriate.
Edit
Of course, if PTSalesPerson
derives from SalesPerson
and its constructor calls the base constructor, this won't work either.