I read some tutorials about a the factory an abstract factory pattern and saw some examples of it. In one of the tutorials i read that the factory pattern could replace major "if" or "switch case" statements and follows the open/closed (solid) principles.
In one of my projects a have a huge "switch case" which i wanna replace by a(n) (abstract) factory. It's already interface based so implementing an factory shouldn't be that difficult but in all the examples i read in tutorials the factory produced a single concrete type based on configuration. Can anyone point me in the right direction how to implement a factory that could produce multiple types based on an enum that follows the Solid principles an replaces the large "switch case"....or am I misinformed and is the "switch case" moved to the factory?
code at this moment:
public interface ISingleMailProcessor : IMailProcessor
{
MailResult ProcesMail(Mail mail);
}
public MailResult GetMailResult(mail)
{
ISingleMailProcessor mailprocessor;
switch (mail.MailType)
{
case MailConnector.MailType.AcronisBackup:
mailprocessor = new AcronisProcessor();
return mailprocessor.ProcesMail(mail);
case ......etc.
}
}