This question was probably posted earlier, but I could not find it.
I have been writing such a thing for so long, I sit down to write something new, and just start typing it as if it were my own template. A project recently appeared, and I discovered that I was looking at my own code and began to think how smelly it looked.
BackgroundInfoIfYouCare
In this particular library, I need to send emails to users. There are still 13 canned letters.
Each letter has its own template (I use the Razor parser, so the templates are written in cshtml). Each email template has a line name key. Each email has its own EF4 request to return the model based on the “membership” object and all associated data.
I have a class that takes a string which is the key of the email template name.
The method will launch the corresponding request and return a list that captures the email template.
The list and template are passed to the parser to combine each membership into a template and returns emails.
EndOfBackgroundInfoIfYouCare
So the real question is ... what is the best way to do this?
One way is to simply use the switch
public List<Membership> Execute(string TemplateKey) {
switch (TemplateKey)
{
case "SomethingExpired":
QueryResult = new SomethingExpiredEmailQuery().ExecuteQuery();
break;
case "SomethingExpireIn30":
QueryResult = new SomethingExpireIn30EmailQuery().ExecuteQuery();
break;
case "FirstTimeLoginThanks":
QueryResult = new FirstTimeLoginThanksEmailQuery().ExecuteQuery();
break;
case "SecurityTraining":
QueryResult = new SecurityTrainingEmailQuery().ExecuteQuery();
break;
case ETC ETC ETC...
}
Another way would be to use an interface
IEmailQuery
void ExecuteQuery()
, Query. .
- :
SecurityTraining SecurityTrainingEmailQuery, ExecuteQuery.
, ?