I have been studying Design Patterns and I am looking to implement them into my latest project.
I am working on a Windows Service that regularly checks a database table for a new entry. Depending on the entry found, the service will perform a number of processes.
Possible processes include:
1) Generate report and send email with report attached
2) Run query and log data to another table
3) Send notification email
What design pattern is best suited? I have been considering the Factory Pattern.
My design process so far...
1) Create Interface
2) Create Abstract class which implements the Interface
3) Abstract Methods:
- CheckTable()
- GenerateReport()
- SendEmail()
4) Factory Design Pattern:
- The client(windows service) asks the Factory for a new object (based of the database entry found)
- The factory instantiates this and returns to the client
- The client then calls the relevant methods to send email or run query.
Does this look correct? Or am I making this more difficult than it is?
Or should I be using the Observor Pattern?
UPDATE:
OK. I have taken your advice and looked for the simplest way of doing this.
Is the below correct? I have created an Interface and then a class to implement this Interface.
There could be a number of different reports/emails to generate. Should these be added as new methods in the Interface?
Do I need an Abstract class?
// interface
internal interface IJobs
{
void SendEmail();
void PublishData();
void GenerateTestReport(string userID, DateTime period);
}
// concrete class
public sealed class JobsFactory : IJobs
{
#region SINGLETON
private static JobsFactory INSTANCE;
private JobsFactory() { }
public static JobsFactory GetInstance()
{
if (INSTANCE == null)
{
INSTANCE = new JobsFactory();
}
return INSTANCE;
}
#endregion
private readonly WorkbookFactory _workbookFactory = WorkbookFactory.GetInstance();
#region IJobs Members
public void SendEmail()
{
// send email
}
public void PublishData()
{
// publish data
}
public void GenerateTestReport(string userID, DateTime period)
{
string reportTestFilePath = this._workbookFactory.BuildTestReportWorkbook(userID, period);
}
#endregion
}