I am trying to create what I am thinking of as a translation class, so that my program can speak to a variety of target platforms. Each platform will be handled by a separate implementation of an abstract class. I have pared things down for the sake of simplicity.
I have an abstract class, with a couple of abstract methods:
abstract class ControllerBase
{
public abstract bool EnableDTMFDetection(string CallID, Party Party);
public abstract bool DisableDTMFDetection(string CallID, Party Party);
}
Subsequently a class (classes) which derive from ControllerBase, and fully implement those methods:
class PlatformOne : ControllerBase
{
public override bool EnableDTMFDetection(string CallID, Party Party)
{
// Do Stuff
return true;
}
public override bool DisableDTMFDetection(string CallID, Party Party)
{
// Do Stuff
return true;
}
}
So far so good. For PlatformOne I am forced to define each of those methods, prescribing how I will send an outgoing message to my target platform.
It is the incoming events that have got me. I need to be able to raise events from within my derived classes. When I add the following to controllerbase:
public delegate void MyEventHandler(object sender, EventArgs e);
public event MyEventHandler MyEvent;
It compiles fine, but I can't raise the event from within my derived class without the error: "The event 'ControllerBase.MyEvent' can only appear on the left hand side of += or -= (except when used from within the type 'ControllerBase')"
So, a) How do I raise my event from within my derived class, and b) can anyone suggest a mechanism for enforcing the wiring up of specified events from within my derived class (a la abstract functions or interface methods). Thank you call :)