title: Handler pattern?
body: <p>I came across several java projects at my company (but this could be done with any OOP language) where we receive an object and depending on some fields we have to do a particular process.
  To avoid doing a huge list of if/else the following pattern is used :</p>
  <p>Create handlers that have a common interface :</p>
  <pre><code>public interface IEventHandler {
      boolean support(Event event);
      void handle(Event event);
  }
  
  public class Handler1 implements IEventHandler {
  
      public Handler1() {
      }
  
      @Override
      public boolean support( Event event ) {
          return event.is1();
      }
  
      @Override
      public void handle( Event event ) {
          //Do something
      }
  }
  
  </code></pre>
  <p>then you &quot;register the handlers&quot; and loop to execute the action :</p>
  <pre><code>List&lt;IEventHandler&gt; handlers = List.of(new Handler1());
  
  for ( final IEventHandler handler : handlers ) {
    if ( handler.support( event ) ) {
      handler.handle( event );
    }
  }
  </code></pre>
  <p>I'm pretty sure this is an anti-pattern but I'm not sure how this pattern is called to find better alternatives.</p>