Martin Fowler wrote interesting article about implementing user defined fields functionality: UserDefinedField. He summarized several patterns:
- Variable state;
- Pre-defined custom fields;
- Dynamic schema.
Variable state means including a hashmap field for user-defined fields. With pre-defined custom fields you specify predefined fields like integer_1, integer_2, text_1… and then use only those which are needed. With dynamic schema you add the code which dynamically changes the schema of data storage (calls ALTER TABLE if it is SQL data storage).
As you probably know Sharepoint also allows users to construct own custom content types, add fields, specify field types, etc. It is interesting to note that it also uses Pre-defined custom fields pattern. E.g. there is AllUserData table (which stores the data of lists and doclibs) in the content database which contains a lot of columns:
- Sharepoint 2007 – 193 columns;
- Sharepoint 2010 – 192 columns;
- Sharepoint 2013 – 4026 columns.
These columns look like bit1, bit2, …, datetime1, datetime2, …, float1, float2, …, int1, int2, …, etc. Now we have common pattern name used for this schema. It is also interesting to note the big grow of the columns in Sharepoint 2013 comparing with previous versions, which however didn’t change list and columns limits in Sharepoint 2013 comparing with 2010 (see Software boundaries and limits).