开发者

Pattern to handle "dynamic enums" that a user could modify (programming language agnostic)

I always face this problem and every time I face this I find a different solutio开发者_高级运维n that doesn't satisfact me. This situation doesn't fit a specific language, but involves a database.

Imagine that you have a situation, in a management application, where the user (not a programmer so) can fill a table which rapresents the programming skill level of it's employees. Than he can assign those values to emplyees in emplyees table.

So the situation in the database is this one:

Table: ProgrammingSkillLevel
  - ID
  - Name
  - Value
Table: Employees
  - ID
  - SomeUselessData
  - ProgrammingSkillLevelID

In a programming fashion I'll usualy do this as an enum (I'll use C#):

enum ProgrammingSkillLevel
{
    Starter = 0,
    Medium,
    Advanced,
}

The advantage of this approach is using Names instead of values, infact if we change the enum into something like this:

enum ProgrammingSkillLevel
{
    Starter = 0,
    Medium,
    Good,
    Advanced,
}

We won't have any problems because we use names. In my database approach I'm using IDs to avoid some byte wastes (I know there is enum type, but the user should fill the table, not me!), not names, so the advantage is definitely lost.

What approach should I use to allow the user to generate what I call "dynamic enums"? Should I use names?

I would like to find a good pattern that will apply to all my projects possibly, because I find this situation very often.


It seems like the question contains the answer, I didn't find a better way to make this through the net, so I'll mark this as an answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜