How to handle a Factory class returning hundreds of class types

What do you do when your factory class can return dozens if not hundreds of class types? I have a factory class that generates commands based on generic input types and variable arguments.

For example:

public class CommandFactory { public static T Create<T>(params object[] args) where T: class, new() { try { if (typeof(T) == typeof(SomeRequest1)) { ... return new SomeRequest1(...) as T; } if (typeof(T) == typeof(SomeRequest2) && arg != null && arg.length == 1 && (arg[0] as SomeParamType) is SomeParamType)) { ... return new SomeRequest2(...) as T; } ... 

by mycall via /r/csharp

Leave a Reply