If I understand what you are trying to do, this is similar to the version of the Multiton Pattern . You may find it helpful to study this.
From Wikipedia example Multi-tone code:
class FooMultiton { private static readonly Dictionary<object, FooMultiton> _instances = new Dictionary<object, FooMultiton>(); private FooMultiton() {} public static FooMultiton GetInstance(object key) { lock (_instances) { FooMultiton instance; if (!_instances.TryGetValue(key, out instance)) { instance = new FooMultiton(); _instances.Add(key, instance); } } return instance; } }
This does not apply directly to your class, but since you are looking for clues, I think it should point you in the right direction.
One caveat to the above code: the GetInstance method will change the dictionary if key not found. Personally, I associate the "Get" prefix with read-only methods. I would rename GetInstance or split it into two methods.
I'm not quite sure what you mean by "creating all existing concrete classes based on its enumerations." Can you clarify this?
source share