I've implemented a generic factory as described hereI need to register elements to the factory hard-code like this:Factory.Register(1, typeof(MyClass));this factory will have to be correlated with a simple domain data type table [id,Display], in this case id 1 is related to MyClass.I was thinking to add a column to that table with the qualified type, so I can simply retrieve the id to types. table will be [id,Display, typeName]and I will use the factory like this:Factory.Register(id, Type.GetType(typeName));I tried it and it's working ok.is this a good design?are there any security flaws?is there a better way to do things?
Factory design pattern - getting the types from a table
design patterns;database design
This ties the db design to the programming language, which, in my opinion, is something you would want to avoid.A simple alternative would be to add a key to the table and have a way to map that key to a type in the programming language of your choice. This may not be such an elegant solution as it may require a switch statement, but it is the better architecture despite the shortcomings of my suggested implementation. This way if you have to use the table in another language, you will be ok.At the very least, add the language agnostic key to your current table and add a cross reference to your fully qualified type name.