title: Reuse conditional statements in sub-classes.
body: <p>I have below classes:</p>
  
  <pre><code>public abstract class Parent {
  
      public abstract boolean checkName(String str);
  }
  
  
  public class Child1 extends Parent {
  
      public static final String NAME = "CHILD1";
  
      @Override
      public boolean checkName(String str) {
          //check input validity:
          if (!NAME.equals(str)) {
              throw new IllegalArgumentException("some thing");
          }
          //...
      }
  }
  
  
  public class Child2 extends Parent {
  
      public static final String NAME = "CHILD2";
  
      @Override
      public boolean checkName(String str) {
          //check input validity:
          if (!NAME.equals(str)) {
              throw new IllegalArgumentException("some thing");
          }
          // ...
      }
  
  }
  </code></pre>
  
  <p>You can see <code>check input validity</code> parts of <code>checkName</code> methods in both classes are same.I know there is no way to move this joint part to abstract <code>checkName</code> method of parent,but is there a way to avoid this repeating?</p>