I haven't done this for a while and I need to find out if this is the best OO way to go. I am having trouble assigning (Setting) the protected properties in a base class in the derived class. I have a solution but I like to know if this is the best design pattern to use or is there a better way?
My Base class
public abstract class EmailBase
{
protected string Subject { get; set; }
protected string To { get; set; }
protected string From { get; set; }
protected virtual void Send()
{
using (MailMessage mail = new MailMessage())
{
// Ok send message here...
}
}
}
I have two different email templates that I need to send so I thought it would be a good idea to have two derived classes, however I will post the code for one derived class for the problem at hand.
public class DerivedOne: EmailBase
{
private const string emailTemplate = "some static text for the body...";
public DerivedOne()
{
}
// This is how I want to set the base class properties,
// but it feels I am just duplicating properties...
public string To
{
set
{
base.To = value;
}
}
And in the controller...
// A send email button was pressed by the user
private bool SendEmail(Model)
{
DerivedOne eMail = new DerivedOne()
{
To = Model.To;
};
}
I tend to not send the properties through the derived constructor as I believe setting up properties tends to be cleaner. However, I know in the derived constructor you can set the base properties : base()
So this is why I have asked, am I wrong to create the same properties in the derived class so the controller can see it? (as the protected properties cannot be seen outside of inheritance of course)