title: Design Pattern to implement Business Rules with hundreds of if else in java
body: <p>I have to implement certain business rules with hundreds of lines of below code</p>
  
  <pre><code>if this
        then this
  else if
        then this
  .
  . // hundreds of lines of rules
   else
        that
  </code></pre>
  
  <p>Do we have any design pattern which can effectively implement this or reuse the code so that it can be applied to all different rules.
  I heard of Specification Pattern which creates something like below</p>
  
  <pre><code>public interface Specification {
  
  boolean isSatisfiedBy(Object o);
  
  Specification and(Specification specification);
  
  Specification or(Specification specification);
  
  Specification not(Specification specification);
  }
  
  
  public abstract class AbstractSpecification implements Specification {
  
  public abstract boolean isSatisfiedBy(Object o);
  
  public Specification and(final Specification specification) {
   return new AndSpecification(this, specification);
  }
  
  public Specification or(final Specification specification) {
   return new OrSpecification(this, specification);
  }
  
   public Specification not(final Specification specification) {
   return new NotSpecification(specification);
  }
  }
  </code></pre>
  
  <p>And then the implementation of Is,And, Or methods but I think this cannot save me writing the if else(may be my understanding is incorrect)...</p>
  
  <p>Is there any best approach to implement such business rules having so many if else statements?</p>
  
  <p>EDIT :  Just a sample example.A,B,C etc are properties of a class.Apart from these there are similar lot of other rules.I wnat to make a generic code for this.</p>
  
  <pre><code>    If &lt;A&gt; = 'something' and &lt;B&gt; = ‘something’ then
      If &lt;C&gt; = ‘02’ and &lt;D&gt; &lt;&gt; ‘02’ and &lt; E&gt; &lt;&gt; ‘02’  then
          'something'
      Else if &lt;H&gt; &lt;&gt; ‘02’ and &lt;I&gt; = ‘02’ and &lt;J&gt; &lt;&gt; ‘02’  then
          'something'
      Else if &lt;H&gt; &lt;&gt; ‘02’ and &lt;I&gt; &lt;&gt; ‘02’ and &lt;J&gt; = ‘02’  then
          'something'
      Else if &lt;H&gt; &lt;&gt; ‘02’ and &lt;I&gt; = ‘02’ and &lt;J&gt; = ‘02’  then 
          'something'
      Else if &lt;H&gt; = ‘02’ and &lt;I&gt; = ‘02’ and &lt;J&gt; &lt;&gt; ‘02’  then 
          'something'
      Else if &lt;H&gt; = ‘02’ and &lt;I&gt; &lt;&gt; ‘02’ and &lt;J&gt; = ‘02’  then 
          'something'
      Else if &lt;H&gt; = ‘02’ and &lt;I&gt; = ‘02’ and &lt;J&gt; = ‘02’  then:
          If &lt;Q&gt; = Y then
              'something'
          Else then 
              'something'
  Else :
  Value of &lt;Z&gt;
  </code></pre>