Problem
  • You are trying to evaluate/execute a complicated boolean expression, involving multiple steps
Solution
  • Provide a method that returns a boolean by evaluating the above complicated expression. 
  • Give it an intention-revealing name, usually in the form of a question. e.g. IsDate(), HasMarkups(), etc. 
  • If the functionality it's trying to execute is a concern of the object itself, make it a property/method on the object itself, rather than the caller code. 
Benefits
  • Simplify complicated boolean tests. Understanding complicated boolean tests in detail is rarely necessary for understanding program flow. 
  • Putting such a test into a function makes the code more readable because
    • the details of the test are out of the way and 
    • a descriptive function name summarizes the purpose of the test. 
  • Both the main flow of the code and the test itself become clearer. 
Trade-off
  • If the test is very simple, keep it inline. 
Before
public void Process(Payment payment)
{
    if (payment.amount > 0 && payment.status != Status.Cancelled && payment.isDue)
    {
        // Process the payment
    }
}
After 
  1. Create a new method in the caller
public void Process(Payment payment)
{
    if (IsValid(payment))
    {
        // Process the payment
    }
}

public bool IsValid(Payment payment)
{
    bool isValid = payment.amount > 0 && payment.status != Status.Cancelled && payment.isDue;
    return isValid;
}
As validation seems more of a concern on the Payment, add a property IsValid on the payment. This is much more readable and flexible, in my opinion. 
public void Process(Payment payment)
{
    if (payment.IsValid)
    {
        // Process the payment
    }
}

class Payment
{
    public bool IsValid(Payment payment)
    {
        get
        {
            return payment.amount > 0 && payment.status != Status.Cancelled && payment.isDue;
        }
    }
}