I'm working on a little proof of concept project for handling and polling the status of transactions, and have had it pointed out that my current web of if statements works OK in the proof of concept stage, but won't hold up or be maintainable as the business logic becomes more complex or more statuses/permutations need to be added.
For a simple example of what I'm working with, here's a function that takes 4 bools as inputs, and different dependent permutations of these will lead to different enum values being returned:
public static TransactionStatus GetStatusForValues(bool isOverdue, bool isUrgent, bool isMember, bool isExisting)
{
if (isExisting)
{
if (isUrgent)
{
if (isMember)
{
return TransactionStatus.Expidited;
}
return TransactionStatus.Declined;
}
if (!isUrgent)
{
if (isOverdue)
{
return TransactionStatus.Active;
}
}
}
if (!isOverdue)
{
return TransactionStatus.Active;
}
return TransactionStatus.Confirmed;
}
(Don't try and read anything into the domain logic here, this is purely made up rules for the benefit of the example)
This example with a relatively small number of input values is kind of convoluted already. Ideally, I would like to be able to implement something that allowed combinations of values to map to a result status, but without having to use a pile of if statements or a switch that could quickly become unmanageable.
An idea that's half-formed in my head is to be able to do some kind of rules engine approach, where individual rules could be passed in to represent the different permutations. I also wondered about being able to use something like C#'s Predicate class to be able to check multiple conditions.
Sounds like you need a pipeline.
Each part of the pipeline can be separate and testable in isolation, but you can add whatever pipeline features are required.