title: Java Listener inheritance
body: <p>I have a java class which fires custom java events. The structure of the code is the following:</p>
  
  <pre><code>public class AEvent extends EventObject {
  ...
  }
  
  public interface AListener extends EventListener {
  
    public void event1(AEvent event);
  
  }
  
  public class A {
  
    public synchronized void addAListener(AListener l) {
    ..
    }
  
    public synchronized void removeAListener(AListener l) {
    ..
    }
  
    protected void fireAListenerEvent1(AEvent event) {
    ..
    }
  }
  </code></pre>
  
  <p>Everything works correctly, but I'd like to create a new subclass of A (call  it B), which may fire a new event. I'm thinking of the following modification:</p>
  
  <pre><code>public class BEvent extends AEvent {
  ...
  }
  
  public interface BListener extends AListener {
  
    public void event2(BEvent event);
  }
  
  public class B extends A {
  
    public synchronized void addBListener(BListener l) {
    ..
    }
  
    public synchronized void removeBListener(BListener l) {
    ..
    }
  
    protected void fireBListenerEvent2(AEvent event) {
    ..
    }
  
  }
  </code></pre>
  
  <p>Is this the correct approach? I was searching the web for examples, but couldn't find any.</p>
  
  <p>There are a few things I don't like in this solution:</p>
  
  <ol>
  <li><code>BListener</code> has two methods one uses <code>AEvent</code> the other uses <code>BEvent</code> as a parameter.</li>
  <li><code>B</code> class both has <code>addAListener</code> and <code>addBListener</code> methods. Should I hide addAListener with private keyword? <strong>[UPDATE: it's not possible to hide with private keyword]</strong></li>
  <li>Similar problem with <code>fireAListenerEvent1</code> and <code>fireBListenerEvent1</code> methods.</li>
  </ol>
  
  <p>I'm using Java version 1.5.</p>