I have a requirement where the the user needs to configure how they would like to get alerted when an error happens. The options they have are the following:
1.) Create an event in the event log
2.) Send an email to an email specified from the user interface
The classes i am using currently use the following interface
interface INotificationSender
{
virtual void SendMessage(string message);
}
my interface is going to be implemented by the following 2 concrete classes
class EmailerNotificationSender: public INotificationSender
{
string m_EmailAddress;
public EmailerNotificationSender(string emailAddress)
{
m_EmailAddress = emailAddress;
}
public virtual void SendMessage(string Message)
{
// Send Message to email specified in member variable
}
}
class EventLogNotificationSender: public INotificationSender
{
public virtual void SendMessage(string Message)
{
// Log message in event log using
}
}
My current interface code looks like the following
public class MyUserinterfaceWindow
{
private INotificationSender m_NotificationSender; // concrete type depends on user interface selection!
public void Button_Click(...)
{
if (emailSelected)
{
m_NotificationSender = new EmailerNotificationSender(textbox.email)
return;
}
m_NotificationSender = new EventLogNotificationSender();
}
public void SendAlert()
{
m_NotificationSender.SendMessaged("SOMETHING BAD HAPPENED");
}
}
**Summary/Question:**
How do i remove the presence of concrete types being instantiated( for example EventLogNotificationSender and EmailerNotificationSender )
**NOTE:** EventLogNotificationSender requires no parameters in it's concrete constructor while EmailNotificationSender's concrete constructor takes a string parameter!