Reducing nested if statements I have a set of rules as follows:

Product One:


If either part is acceptable, update both parts


Product Two:


If either part is acceptable, and one age is > 55, update both parts
If either part is acceptable, and neither age is > 55, then update whichever part needs updating (or both)


I know it's not the most nested if statements you'll see, but it feels like I'm repeating code unnecessary and there should be a simpler version of what I've attempted.

The Code:

 if (this.isAcceptablePartOne || this.isAcceptablePartTwo) {
    if (this.productName.equals(PRODUCT_ONE)) {
        updatePartOne();
        updatePartTwo();
    }
    if (this.productName.equals(PRODUCT_TWO)) {
        if (Math.max(this.ageLifeOne, this.ageLifeTwo) &gt; 55) {
            updatePartOne();
            updatePartTwo();
        } else {
            if (this.isAcceptablePartOne) {
                updatePartOne();
            }
            if (this.isAcceptablePartTwo) {
                updatePartTwo();
            }
        }
     }
 }
From the requirements


  I have a set of rules as follows:
  
  Product One:
  
  If either part is acceptable, update both parts 
  
  Product Two:
  
  If either part is acceptable, and one age is > 55, update both parts
  
  If either part is acceptable, and neither age is > 55, then update
  whichever part needs updating (or both)


Follows the next, almost literal, straightforward implementation:

Straightforward implementation

So, you could implement this using two Checkers, a Product1Checker and a Product2Checker. 

if (this.productName.equals(PRODUCT_ONE))
{
    new Product1Checker().check(this);
}
else if (this.productName.equals(PRODUCT_TWO))
{
    new Product2Checker().check(this);
}


Like this:

class Product1Checker 
{

    public check (Product product)
    {
         if (product.isAcceptablePartOne || product.isAcceptablePartTwo) 
         {
               product.updatePartOne();
               product.updatePartTwo();
         }
    }
} 


Alternative approach

You could have the Checkers implement a ProductChecker interface. Also, each ProductChecker can have a boolean method indicating if this checker applies to a product. Then you can just add all the checkers to a Set, check if they are applicable, and if so, run them on the product

interface ProductChecker
{
    boolean check     (Product p);
    boolean appliesTo (Product p);
}

Set&lt;ProductChecker&gt; checkers = new HashSet&lt;ProductChecker&gt;();
checkers.add(new Product1Checker());
checkers.add(new Product2Checker());

for (ProductChecker checker: checkers)
{
      if (checker.appliesTo(this))
      {
          checker.check(this));
      }
}