J
Jay Douglas
Greetings,
I have a Windows form application that (naturally) instantiates all sorts of
objects. I have a base object that contains an event. Lots of other
objects inherit from this event. When the base object or any derived object
is instantiated I would like to automagically start listening for the event.
An example and a further explanation follows:
public delegate NeedFoodDelegate(object sender, EventArgs args);
public class Animail
{
public event NeedFoodDelegate OnNeedFood;
public void StartHunger()
{
if (OnNeedFood != null)
OnNeedFood(this, new EventArgs());
}
}
public class Cat : Animal
{
}
public class Dog : Animal
{
}
Now the winform application will be creating Cat, Dog, and Animal
frequently. I would like to have one event handler for ALL instances. It's
virtually impossible for me to explicitly define and event handler for each
object as Cat and Dog may be many layers deep in the object hierarchy.
I may be using the wrong design pattern all together to monitor the events
in all the object. I was thinking about using the MSMQ but these events and
notifications do not need to span multiple AppDomains so I figure MSMQ would
be over kill.
I hope I described this clearly.
Any and all suggestions are appreciated.
Thanks,
Jay
I have a Windows form application that (naturally) instantiates all sorts of
objects. I have a base object that contains an event. Lots of other
objects inherit from this event. When the base object or any derived object
is instantiated I would like to automagically start listening for the event.
An example and a further explanation follows:
public delegate NeedFoodDelegate(object sender, EventArgs args);
public class Animail
{
public event NeedFoodDelegate OnNeedFood;
public void StartHunger()
{
if (OnNeedFood != null)
OnNeedFood(this, new EventArgs());
}
}
public class Cat : Animal
{
}
public class Dog : Animal
{
}
Now the winform application will be creating Cat, Dog, and Animal
frequently. I would like to have one event handler for ALL instances. It's
virtually impossible for me to explicitly define and event handler for each
object as Cat and Dog may be many layers deep in the object hierarchy.
I may be using the wrong design pattern all together to monitor the events
in all the object. I was thinking about using the MSMQ but these events and
notifications do not need to span multiple AppDomains so I figure MSMQ would
be over kill.
I hope I described this clearly.
Any and all suggestions are appreciated.
Thanks,
Jay