Hello. I ask your advice here on what matter. I have a class hierarchy
enum SomeEnum { First, Second } abstract class BaseClass { private SomeEnum ActionId { get; set; } protected BaseClass(SomeEnum actionId) { ActionId = actionId; } public static T GetById<T>(SomeEnum actionId) where T : BaseClass { switch(actionId) { case SomeEnum.First: return new DerivedFirst(actionId) as T; case SomeEnum.Second: return new DerivedSecond(actionId) as T; default: throw new ArgumentException(); } } } class DerivedFirst : BaseClass { public DerivedFirst(SomeEnum actionId) : base(actionId) { } } class DerivedSecond : BaseClass { public DerivedSecond(SomeEnum actionId) : base(actionId) { } }
The problem is that in the abstract class BaseClass there is a static method that returns an instance of the class DerivedFirst or DerivedSecond depending on the type of the actionId parameter. It seems to me that I wrote a bad decision. Maybe you can tell something better, nothing comes to mind ((