DWT2

Jacob Carlborg doob at me.com
Sun Apr 10 04:09:52 PDT 2011


On 2011-04-08 16:45, Steven Schveighoffer wrote:
> On Fri, 08 Apr 2011 10:36:39 -0400, Andrej Mitrovic
> <andrej.mitrovich at gmail.com> wrote:
>
>> On 4/8/11, Bruno Medeiros <brunodomedeiros+spam at com.gmail> wrote:
>>> On 05/04/2011 04:54, Andrej Mitrovic wrote:
>>>> You have to be kidding me. Who writes code like this?
>>>>
>>>> http://i.imgur.com/BBQde.png
>>>
>>> What's wrong with it? Do you mean the anonymous classes with all the
>>> fields and contructors for passing the variables in the enclosing scope?
>>>
>>> --
>>> Bruno Medeiros - Software Engineer
>>>
>>
>> I don't understand the need to create huge anonymous classes. If
>> you're going to create or override so many methods, you might as well
>> create a new class instead of embedding one in the call.
>>
>> Maybe that's a standard way of doing it in Java, but I'd never code
>> like this. Maybe it's because I don't depend on an IDE, and like to
>> keep my code clean. I'm not a fan of deeply nested code.
>
> I think the reason it looks like this is because Java does not have
> delegates. Anonymous delegates are much easier to read, and also do not
> take up heap space.
>
> If anything, I'd say a very worthwhile project would be to change all
> the callback interfaces and anonymous classes to delegates.
>
> -Steve

DWT already have a way to pass a delegate to a function expecting an 
interface. It will create a class the implements the interface and then 
delegate the call to, in this case "handleEvent", to the delegate. Have 
a look at the bottom of: http://dsource.org/projects/dwt/wiki/DiffToOriginal

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list