Seven Low-Cost Ways to Improve Legacy Code
Subject:   Re: 5: Removing Anonymous Inner Classes
Date:   2004-06-04 04:57:59
From:   Robert Simmons Jr. (Kraythe)
Response to: Re: 5: Removing Anonymous Inner Classes

I would disagree with declaring a class that can be used only once on general OO design principles. You may dislike the IF structure but actually you are incurring massive overhead in the class declaration in order to avoid the if structure. In addition, the special access rules for anonymous classes makes them often difficult to manage and debug.

Furthermore, of you have 35 ifs in your actionPerformed method, you might really want to think about the usability of your GUI and see whether it cant be improved. If It cant, then there are other options using reflection that are quite fast for dispatching.

Naturally this is my opinion. However, it is an opinion that has solidified over years of consulting work and unrelenting issues with anonymous listeners.