B
beginwithl
hi
I’m a bit confused about when I should implement events and when
delegates.
BTW: I realize that event is only a modifier that gives controlled
access to its privately declared delegate
1)
a) As far as I understand it, we should choose events over delegates
when encapsulation is of importance and thus we want only for
publisher class to be able to call subscribed methods?
b) But, while it is true that event can only be invoked from within
the class that declares it, couldn’t the same level of encapsulation
be achieved with a delegate object also, assuming we declare it as
being private?
2) In any case, I still don’t know based on what criteria I should
decide when I need the kind of encapsulation ( and thus safety ) the
events offer, and when using the delegate objects would suffice?
3) Are delegates really all that useful by themselves, or do we most
of the times use events? If so, why?
thank you
I’m a bit confused about when I should implement events and when
delegates.
BTW: I realize that event is only a modifier that gives controlled
access to its privately declared delegate
1)
a) As far as I understand it, we should choose events over delegates
when encapsulation is of importance and thus we want only for
publisher class to be able to call subscribed methods?
b) But, while it is true that event can only be invoked from within
the class that declares it, couldn’t the same level of encapsulation
be achieved with a delegate object also, assuming we declare it as
being private?
2) In any case, I still don’t know based on what criteria I should
decide when I need the kind of encapsulation ( and thus safety ) the
events offer, and when using the delegate objects would suffice?
3) Are delegates really all that useful by themselves, or do we most
of the times use events? If so, why?
thank you