Let's say you need a class which will hold a cost (of a call, for example). Then you will need a class which manipulates the call (i.e. by adding a tax.)
public class RawCall
{
public decimal m_dCost;
public RawCall( decimal dmInitialCost)
{
m_dCost = dmInitialCost;
}
public virtual decimal GetCost()
{
return m_dCost;
}
}
public class ProcessedCall : RawCall
{
public int m_iTaxPercent;
public new decimal m_dCost;
public ProcessedCall( decimal dmCallCost) : base( dmCallCost)
{
m_dCost = dmCallCost;
}
public void ApplyTax()
{
m_dCost = m_dCost * ( 100 + m_iTaxPercent) / 100;
}
public new decimal GetCost()
{
return m_dCost;
}
}
Now, let's assume you need to display the cost of the call without tax and with tax in the same report/form/etc..
You can simply do that with the following code:
ProcessedCall aProcCall = new ProcessedCall( 10);
RawCall aRawCall = (RawCall)aProcCall;
aProcCall.m_iTaxPercent = 20;
aProcCall.ApplyTax();
MessageBox.Show( aProcCall.GetCost().ToString()); //Will show 12
MessageBox.Show( aRawCall.GetCost().ToString() );//Will show 10