title: Java - Design Pattern to solve multiple conditionals logic
body: <p>Say I have a Utility class. In this class, I am exposing only 2 public functions:</p>
  
  <pre><code>public static boolean checkCustomerEligiblity(HttpServletRequest request)
  public static boolean checkCartEligiblity(HttpServletRequest request)
  </code></pre>
  
  <p>Each of these method’s implementation is really messy (I did not implement this method). For future reference I want to understand the best way we can implement in such scenarios.</p>
  
  <p>Point to also remember is that in cases of FALSE conditions we are not supposed to exit or return. We have to record the FALSE condition with a reason and proceed with the rest of the checks.</p>
  
  <pre><code>public static Boolean checkCustomerEligiblity(HttpServletRequest request) {
        if (Flags) { //Check if Flags are ON, only then proceed with rest         
          if (Type of customer) { //Restrict only to certain type of customers
            if (Customer within limit) { //Check customer’s available cash limit in account
  
            } else reasons.add(“Customer not within limit”);
          } else reasons.add(“Customer type not supported”);
  
          if (Customer account is NULL) {…}
          if (Customer skipped verification with photo ID) {…}
          if (Customer’s organization has opted in the plan) {…}
          if (Customer’s bill is combined bill) {…}
          if (Customer has past due on his account) {…}
          if (Customer’s credit rating is good) {…}
          if (Customer’s account is active) {…}
          if (Customer has not opted for this plan already) {…}
  
          ...around 15-20 If conditions more...
        }
  }
  </code></pre>
  
  <p>The same structure goes for the checkCartEligibility() method.</p>
  
  <p>My question is – </p>
  
  <p>1) Will it be too unwieldy to use Strategy or Command design pattern to implement the above?</p>
  
  <p>For instance, </p>
  
  <pre><code>public interface Validator {
     Boolean validate(HttpServletRequest);
  }
  
  public class CustomerCreditValidator implements Validator {…}
  public class FlagValidator implements Validator {…}
  public class AccountVerificationValidator implements Validator {…}
  public class OrderTypeValidator implements Validator {…}
  public class CartValidator implements Validator {…}
  </code></pre>
  
  <p>…so on with around 10-15 more validator classes (I can combine couple of checks in the same class to lower down the number of such classes).</p>
  
  <pre><code>List&lt;Validator&gt; validators = new ArrayList&lt;&gt;();
  
  validators.add(new CustomerCreditValidator());  
  validators.add(new FlagValidator());
  validators.add(new AccountVerificationValidator());
  validators.add(new OrderTypeValidator());
  validators.add(new CartValidator());`
  </code></pre>
  
  <p>…so on for other classes.</p>
  
  <pre><code>for (Validator validator : validators) {
     boolean result = validator.validate(request);
     if (result) {
        ...
  }
  </code></pre>
  
  <p>2) If the above approach is going to be too cumbersome too, what is/are the other design pattern(s) would you propose the implement the above logic? </p>
  
  <p>3) By the way, each of the validation checks are private, so can I have all the above validator classes as inner classes only? </p>
  
  <p>Much appreciate any help!</p>