You have quite a few options, with a static event probably being the
best option. Having static firing code is probably also a good action
to take, since it serializes your eventing code.
The only "gotcha" you are going to run into is that you can only have
a single *collection* of your class. Since you are using a static, if
any of your classes fires the event, then whomever is listening will
hear it. This means you can't provide any form of partitioning. An
example might be:
Say you have 10 people on a stock trading floor. All 10 people
initially listen to everything to figure out what they are interested in.
As time progresses, they eventually realize they only need to listen
to a portion of the floor that contains information they are interested
in. This would be identical to 10 event consumers that eventually
only want to listen to a subset of events.
Now, if you don't need the above partioning and can guarantee you'll
never need it, then move forward. If you do need partitioning then
start thinking back to that controller object you were thinking about.
At that level you can have a ClassSet that contains all instances of your
classes, and the ClassSet can be coerced into giving up ClassSubSet's
that only contain specific instances. A ClassSet might have a certain
frequency that it allows broadcasts on, say 1 every second, while the
ClassSubSet could allow more frequent broadcasting since the theoretical
number of consumers would be less.
Loads of options, and a very interesting problem. Keep us aprised for what
you are doing.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog:
http://weblogs.asp.net/justin_rogers
"Colin Cashman" <cd*@gis.net> wrote in message
news:Jrwxc.22778$Sw.16502@attbi_s51...
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