C
Colin Cashman
In a program I'm writing, I have a class that generates a certain
event. However, there may be dozens or even hundreds of instances
of this particular class, which makes adding and removing handlers
to each instance a pain. Rather than go down that route, I was
thinking of making the event static, so I would only need to add my
handlers once, to the static event, which I can then trigger from
inside my class.
That leaves me with two questions:
1. Is there a better way to handle this than using static events?
(I thought of having another class own a "master" event, but that
simply introduces more connecting code, and is a bit messier when
it comes to encapsulation.)
2. If this IS the best way, are there any "gotchas" or problems
I should be aware of when using static events?
Thanks in advance!
Colin
event. However, there may be dozens or even hundreds of instances
of this particular class, which makes adding and removing handlers
to each instance a pain. Rather than go down that route, I was
thinking of making the event static, so I would only need to add my
handlers once, to the static event, which I can then trigger from
inside my class.
That leaves me with two questions:
1. Is there a better way to handle this than using static events?
(I thought of having another class own a "master" event, but that
simply introduces more connecting code, and is a bit messier when
it comes to encapsulation.)
2. If this IS the best way, are there any "gotchas" or problems
I should be aware of when using static events?
Thanks in advance!
Colin