C# code using factory design pattern