Abstract Factory Using Generics: Is Explicitly Converting a Specified Type to Generic a Bad Practice
Posted
by Merritt
on Stack Overflow
See other posts from Stack Overflow
or by Merritt
Published on 2010-04-12T17:03:19Z
Indexed on
2010/04/12
17:33 UTC
Read the original article
Hit count: 373
The question's title says it all. I like how it fits into the rest of my code, but does it smell?
public interface IFoo<T>
{
T Bar { get; set; }
}
public class StringFoo : IFoo<string>
{
public string Bar { get; set; }
}
public static class FooFactory
{
public static IFoo<T> CreateFoo<T>()
{
if (typeof(T) == typeof(string))
{
return new StringFoo() as IFoo<T>;
}
throw new NotImplementedException();
}
}
UPDATE: this is sort of a duplicate of Is the StaticFactory in codecampserver a well known pattern?
© Stack Overflow or respective owner