"mathon" <ma****@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Hello,
could anybody explain me the advantages and disadvantages of delegation
and
the advantages and disadvantages using event-listeners? - both related to
the
treatment of events.
thanks in advance
I assume you mean delegates and not general delegation, anyway. Delegates
are basically method pointers, they allow you to, fairly loosely, pass
around a reference to a bit of code. Their main advantages is that you don't
have to implement an interface or do anything except match the signature of
the delegate to use it. Their main drawback is they don't carry state well.
You can use classes with a delegate to carry state, but its not accessible
by the reciever and it can be a bit obscure at times. There is also the
chance your delegate will be invoked on a different thread which means you
may have to think about delegates in scenarios where you are working with
threads.
Event listeners, which are delegates, follow the same pattern. I can't thnk
of any additional disadvantages since they are virtually the same thing.