title: Java abstract class - how can I best solve this?
body: <p>I have an abstract class 'TopHandler'. There are two classes that extends TopHandler: 'UserHandler' and 'MerchantHandler'. </p>
  
  <p>I have a method sendMessage() which I'm unsure where to place. One option is to put it inside TopHandler and create an object of either UserHandler or MerchantHandler, like this: </p>
  
  <pre><code>public abstract class TopHandler {
  
      //Other methods... 
  
      public void sendMessage() {
  
          TopHandler handler;
          if (message.equalsIgnoreCase("User")) {
              handler = new UserHandler();
              //Call UserHandler implementation of abstract methods
          } else {
              handler = new MerchantHandler();
              //Call MerchantHandler implementation of abstract methods 
          }
      }
  }
  </code></pre>
  
  <p>My other option is to make sendMessage() abstract and have both classes implement it, but this does create some duplicate/very similar code. </p>