I have a class Transaction
with subclasses Income
and Expense
which have a property category
. Incomes and expenses have distinct categories, i.e. an IncomeCategory
and ExpenseCategory
. I need a list of both incomes and expenses, so I create a list of Transactions. But I need to also access their category, so Transaction
also needs a category property. Since the values a category can take on is finite, enums or sealed classes would be very practical. But I need something where the supertype is interchangeable with the subtype.
Is there a way to specify a general category, so that the Transaction class can accept either of IncomeCategory
or ExpenseCategory
as a parameter?
P.S.: Sorry for the horrible title, I couldn't think of a better way to describe my problem