Hi All,
I have 3 classes. class A, B and C. with all 3 classes having the event OnSomethingHappend.
A.OnSomethingHappend, B.OnSomethingHappend and C.OnSomethingHappend
C had a member of type B
B has a member of type A
So:
C
B
A
How can i chain the event OnSomethingHappend from A all the way to C via B
So that if the event fires in a it is automaticly bubled up to C and fires there aswell.
I want to bind the events somehow rather then passing on the event.
S0 what i dont want to do is create an event handler in class C that responds to the event in class B that is fired when the event in class A happens.
So code i dont want to use is like this for
class C
B.OnSomethingHappend += new B.SomethingHappend(_B_OnSomethingHappend);
void _B_OnSomethingHappend(object sender, EventArgs eventArgs)
{
//do stuff when event in class A fired
}
Class B
A.OnSomethingHappend += new A.SomethingHappend(_A_OnSomethingHappend);
void _A_OnSomethingHappend(object sender, EventArgs eventArgs)
{
OnSomethingHappend(this, new EventArgs());
}
Is there a more cleaner way to bind/chain events?
Your factory might look something like:
public class ABCFactory
{
public ABCFactory()
{}
public A create()
{
A = new A();
B = new B();
C = new C();
A.eventName += B.Handler //In whatever order you wanted to fire the events
B.eventName += C.Handler
return A;
}
}
Now only the factory knows about A, B, and C's events. A does not depend on B and B does not depend on C. This method is much cleaner and decouples A, B, and C nicely.
-Adecus