In all the Java source code examples I have looked at the listeners have always been declared in inner classes.
Why – what is the reason for coding the classes like this instead of having the listener(s) in their own seperate *.java file \ class?
Would having seperate classes for the listeners be considered a bad design?
If it’s not a bad design \ sackable offence could someone please post a short example demonstrating how to implement this?
Thank for reading.
Edit\Update – 10.8.2010:
Thanks to all who took the time to reply. Lots of insightful points to consider.
Having read all the answers I think that unless there is a very good reason for doing otherwise it is better and easier to declare listeners as inner classes.
Apologies for not coming back to this question sooner, but I don’t always have as much time for coding as I’d like 🙁
Happy coding.
Good reasons for using inner classes:
Possible reasons for using top level classes:
In short: inner classes are usually preferred, but if you have good reasons then it can be perfectly sensible to create top level classes instead.