What are the benefits/drawbacks of using (Method 1) a separate listener classes (maybe an inner class) like:
private ClassAAL implements ActionListener
{
...
}
private ClassAWL implements WindowListener
{
...
}
versus (Method 2) implementing the interface
public class ClassA implements ActionListener, WindowListener
versus (Method 3) setting a listener using an Anonymous class for each element that needs a listener.
btn.addActionListener(new ActionListener()...);
Question: What are the Benefits and Drawbacks of each of these methods? Are there performance benefits, or any Design Patterns that recommend one over the other? or any other benefits?
I can see that:
- The first method is cleaner
- The second method is more compact
- The third method adds the listener code right at the element.
Note: I saw a question Nested class vs implements ActionListener on this; but most answers seem to give what the person uses rather than any advantages/disadvantages of each method.