title: Design pattern for replacing nested if statements (arrow anti-pattern)
body: <p>I noticed my code looks really ugly, and is hard to maintain. Basicaly i need do to some person check. Pseudo code is like this (BTW i can't "cut" anything in query, and it's not realy the point of my question):</p>
  
  <pre><code>List&lt;Person&gt; persons = getPersonsBySomeQuery();
  
  if (checkAnyPersonExists(persons)) {
    if (atLeastOneWithGivenNameExist(persons)) {
      if (noOneWithOtherNameExists(persons)) {
        filteredPersons = filterPersonsWithGivenName(persons);
        if (singleName(filteredPersons)) {
          // single person found
          if (someParameterFromQueryIsTrue) {
            if (someComplicatedLogicIsOK) {
              // found exactly one person, all OK!!!
            } else {
              // found exatcly one person with given name, but not OK
            }
          } else {
             // found exactly one person but parameter from query is not OK
          }
        } else {
          // found only persons with given name, but more then one
        }
      } else {
        // found person(s) with given name, but also some with different name
      }
    } else {
      // found person(s), all have different name
    }
  } else {
    // noone found
  }
  </code></pre>
  
  <p>So i don't have that much experience with design patterns, but i read about them, and i started thinking i could implement Chain of Responsibility pattern. Like, every if-else could be one element in chain, and also this filter element on line 6 could also be "Chainable".</p>
  
  <p>In the end it could look something like:</p>
  
  <pre><code>AbstractChainElement getCheckChain() {
     return new CheckAnyExist(
            new CheckOneWIthGivenNameExist(
            new CheckNoOneWithOtherNameExist(
            new FilterOnlyGivenName(
            new CheckIsSingleName(
            new CheckOtherParameters(
            new CheckWithSomeComplicatedLogic()))))));          
  }
  
  getCheckChain().doChain(persons);
  </code></pre>
  
  <p>Do you think it's good way to do it or is there anything more elegant?</p>
  
  <p>With this i could construct chain for checking for different check types also, using factory or even abstract factory pattern.</p>
  
  <p>Something like:</p>
  
  <pre><code>FactoryCheckThesePersonsByTheseParameters implements AbstractFactory {
  
       List&lt;Person&gt; getPersons() {
         // get persons with THIS query
       }
  
       AbstractChainElement getCheckChain() {
         // check persons THIS way
       }
  }
  
  FactoryCheckThatPersonsByThatParameters implements AbstractFactory {
  
       List&lt;Person&gt; getPersonsBySomeParameters() {
         // get persons with THAT query
       }
  
       AbstractChainElement getCheckChain() {
         // check persons THAT way
       }
  }
  </code></pre>