On Mon, 22 Sep 2008 13:30:01 -0700, Paul <Pa**@discussions.microsoft.com>
wrote:
sorry. what im asking is what is the best practice way (if there is one)
of
getting the events from the bottom to the top.
Out of context, it's my opinion that describing a "best practice" isn't
possible. There are surely situations where proxying makes a lot of
sense. That said...
(1) have events raised at the bottom and handled in the middle and then
re-raised in the middle and handled again at the top. this seems like
duplication of effort and like re-throwing exceptions im not sure if it
is
frowned upon or not.
I think if you can avoid this, you should. You won't always be able to,
but you're right that it involves extra overhead.
(2) i could pass the event around from the middle to the bottom. again im
not sure if i like the idea of passing events around. im not sure if
this has
impacts from a thread safety / overhead standpoint.
You can't pass an event. It's not something that is instantiated,
referenced, etc. So obviously this approach is not valid.
A third approach, one I mentioned before, is valid: having the middle
class subscribe a method of the top class to an event of the bottom
class. This would rely on either the top class exposing the handler
publicly, or having the top class provide a delegate instance (perhaps via
a property or method that returns the delegate) that can be attached to
the bottom class's event.
It's not a perfect metaphor, but I think of this third approach as being
more of a "push" approach, and the first approach as being more of a
"pull" approach. That is, in the third approach, the middle class is
pushing events onto the top class. In the first approach, the top class
is pulling events from the middle class.
So, if you have a preference between "push" and "pull", that could help
guide your design decision as well.
You could in fact implement an intermediate design in which the top class
explicitly passed a delegate instance to the middle class, rather than
waiting for the middle class to ask it for one, and then relied on the
middle class to subscribe that delegate instance to the bottom class's
event. In that respect, the top class is doing a bit of pulling by
driving the subscription process, while still allowing the middle class to
do a bit of pushing (by taking care of the subscription to the actual
event).
Pete