my application has the following structure:
public class Transaction
{
public int TransactionID { get; set; }
public TransactionTypes Type { get; set; } // Enum for the type of transaction
public decimal Amount { get; set; }
public virtual decimal GrandTotal { get; set; } // In this case this would simply be the Amount
}
public class MembershipTransaction : Transaction
{
public decimal ExtraAmount { get; set; }
public override decimal GrandTotal { get { return base.GrandTotal + ExtraAmount; } }
}
I was wondering whether the GrandTotal against the transaction should include the ExtraAmount automatically. The benefits of this is that if i get all the transactions the GrandTotal figure will be correct regardless of the type of transaction. With the above logic i currently have to switch over each transaction type and return the GrandTotal for the derived type.
I’d appreciate it if someone could clear this up for me. Thanks
A Grand Total is a Grand Total, and as such it would make sense if it included the
ExtraAmount. This also makes sense in the context that code may only require knowledge about the base classTransactionto obtain a correctGrandTotalvalue.As a side note; what purpose does the
TransactionTypesenum have? Is it not enough to examine the type of the transaction object itself?