- Check all usages of the enum type
- Check all usages of the containing class
We have a class Account
, which contains a property AccountType
The account type is Credit
or Debit
, and we want to add a type Mortgage
When we want to search for debt a person has, we now return Accounts
where Type
is Credit
.
var debt = accounts.Where(acc => acc.AccountType == AccountType.Credit)
This logic breaks when we add Mortgage
type, because a mortgage is also a form of debt.
To resolve this:
- Search for all usages of the
AccountType
enum and see where logic needs to be updated
There's also the option where the query could be setup like this:
var debt = accounts.Where(acc => acc.AccountType != AccountType.Debit)
Note the != here
- Check all usages of the
Account
class (all classes that useAccountType
), and see where new logic needs to be implemented
Example: to query the balance of the account, we query all Accounts for a person. However, we only want to see liquid funds, so we should add an introduction of a filter to only return Accounts where Type is Credit
or Debit
Imagine this code:
var spendableBalance = accounts.Sum(x => x.Balance);
There is no usage of the AccountType here, so using #1 doesn't apply here, as it doesn't show up in our search results. The way to find where the logic needs to be introduced is to search for all usages of the Account class.
- Find where the enum is used, and query all usages of those classes. Where logic needs to be introduced, introduce it.
- When introducing logic, you can add equality and inequality checks. When is
Type == Credit || Type == Debit
better thanType != Mortgage
- What about libraries? You don't know the ways a consumer uses your code.