When modeling your business domain, you may sometimes run into a situation, where two or more fields have different but very similar lists of possible values with a lot of values in common. Another scenario is when you may want to tweak different values in a certain list for different installations of your system. You can potentially model such scenarios by creating one all-inclusive list of possible values and then use additional properties to control what appears in each list, but Xomega provides a more simple and powerful solution to that.
To address these and other types of scenarios, Xomega allows you to inherit one enumeration from another and then add or override any items or properties as needed. Here are the steps that will let you achieve that.
- Define a base static enumeration in the model, which you want to inherit from.
- For the enumeration that you want to inherit from the base enumeration, add an enum element to the enums grouping element in the most appropriate file. Typically it's recommended to declare the enumerations in the file where they are used the most often.
- Give the inherited enumeration a unique name by setting the name attribute.
- Set the base attribute to the name of the enumeration that you want to inherit from.
- To add a new item, a property value of a specific item or an additional property, add a corresponding element following the regular enumeration structure.
- To remove an item, a property value of a specific item or a property definition from the base enumeration, add a corresponding item, property value or property definition with the same identifying attribute(s) following the regular enumeration structure, and set the overrideAction attribute to delete. The identifying attributes for different types of elements are as follows: for an item and a property definition it is a name attribute; for item property values it is a ref attribute coupled with a value attribute for multi-value properties.
- To override an item, a property value of a specific item or a property definition from the base enumeration, add a corresponding item, property value or property definition with the same identifying attribute(s) following the regular enumeration structure, and set the attributes that you want to override or add. If you also want to remove the attributes that you don't include here, or if you want to override all the child elements, such as description stored in the doc > summary element, then you need to replace the whole base element with the current one by setting the overrideAction attribute to replace.
- To remove all additional properties, set the overrideAction attribute to delete on the properties element.
- To replace additional properties with a new set of properties, set the overrideAction attribute to replace on the properties element.
- Add enumeration's description inside the nested elements doc > summary of the enum element to provide more details about the enumeration for developers and users.
The following snippet demonstrates an enumeration that inherits from the standard
operators enumeration, defines a new property, adds a new item, overrides the value of the existing
Contains item, and adds a new property value, deletes an existing property value and overrides another property value (
sort order) for that item.
Code:
<enum name="my operators" base="operators">
<properties>
<property name="new property"/>
<property name="addl props" multi-value="true" overrideAction="replace"/>
</properties>
<item name="Contains" value="CONT">
<prop ref="new property" value="abc"/>
<prop ref="addl props" value="1" overrideAction="delete"/>
<prop ref="sort order" value="20"/>
</item>
<item name="New Item" value="NEWVAL"/>
</enum>