Open Enumerations

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

An open enumeration should be used when an enumerated set of values is required and the values must be modifiable post-deployment. Because the values may change over time, applications should not, as a rule, take a dependency on the initial set of values.

Design Pattern

An open enumeration is defined using an extent with an initial set of values. As the enumerated values are held as data in an extent they can be added to, changed or deleted after deployment. An open enumeration can be “closed” by securing the data to prevent update, which may be a preferable way to represent large fixed enumerations.

The enumeration extent can be defined with a single identifying field that holds a meaningful value, or with a codified value or alias used as the identifier, and a meaningful value stored in a separate field. Storing a meaningful value alone is appropriate if storage efficiency is less important and allows a reference field to be interpreted without querying the enumeration. If an opaque alias is used, then the extent must be queried to interpret or retrieve the meaning.

In the following example, the enumeration ContactKinds is defined as an extent that contains meaningful text values, while PhoneUses uses a compact integer alias with the meanings stored in a separate field.

module Patterns.Enumerations.Open
{
    People : 
    {
        Id : Integer64 = AutoNumber();
        
        Name : Text where value.Count <= 100;
        
        ContactKind : ContactKinds;
                     
        Phone : (Text where value.Count <= 20)?;
        
        PhoneUse : PhoneUses;
   
    }* where identity Id;

    ContactKinds : 
    {
        Value : Text#20;
        
    }* where identity (Value)
    {
         {Value = "Customer"},
         {Value = "Colleague"},
         {Value = "Friend"}
    }   

    PhoneUses : 
    {
        Id : Unsigned8;
        
        Value : Text where value.Count <= 20;  
    
    }* where 
        identity Id,
        unique Value
    {
        {Id = 1, Value = "Home"},
        {Id = 2, Value = "Work"},
        {Id = 3, Value = "Unknown"}
    }
    
}

While values and their meanings can be added, changed or deleted in an open enumeration post-deployment, such changes should be made with care. If required, a constraint could be written that verifies that a set of well-known ‘initial’ or ‘base’ values exist in the extent while still allowing new values to be added or changed.

See Also

Concepts

Closed Enumerations
Modeling Patterns and Guidelines