We have some tables for domain type values, ie Customer Type, operation type etc..
it’s built like: TypeID, Display,…
This way the web app can show the Display to the user and send the ID to the server side code, there it can be related to an enum or sent to a factory in order to create an instance by the ID.
I was thinking to add an information column for creating the Type (ie its type if assembly is loaded) so that the Activator could create the instance, this way I can narrow the configuration to just the above table.
before adding the column I have to define the types in the code specifically as well like so:
Factory.Register(id, typeof(MyClass));
if I will add that column I could make it :
Factory.Register(id, Type.GetType(StringValueFromDB));
it is working alright for me in the moment, so my questions are:
is it following good principles?
does it have any kind of flaw?
btw, each factory is a generic factory as mentioned here
Do you actually need to store a type name in your table? From what I understand the
TypeIDis strongly linked to aTypein your codebase whichFactory.Register(id, typeof(MyClass));defines just fine.If you wanted to store the type name in the table for e.g. the ability to change implementations on the fly then perhaps your approach would be useful. But personally I think it is unnecessary as you would probably have to make changes to the rest of your code to accommodate any type changes you make anyway.