The attribute mechanism provides a way to attach named characteristics or properties to other data. These characteristics can themselves be any type of data. For example, you can attach the font size "24" to a range of text data as an attribute of that data. The attribute name would be font
size
and the data it names would be the value 24.
Consider categories of names to be an optional extension of the name itself. Unless otherwise noted, assume that name refers to both an attribute's name and its category. See "Reducing attribute access time using categories" on page 164 for more information.
Figure 38
The name can be specific to the instance, shared by all instances of a class, or shared among instances of several related classes. The wrapping itself is performed when an attribute is instantiated, and is a completely dynamic operation. All attribute creation and deletion is performed at runtime.
NOTE While an attribute of a given class does not necessarily have a given name, attributes of a given name must always be of a given class.
The data portion of an attribute is completely arbitrary. There is no protocol in any of the attribute classes that deal with attribute data. The assumption is that if you know enough to ask for a particular attribute, then you know the class of that attribute and the form of its data. Derived classes usually add their own protocol to access the wrapped data.
Typically, you use groups of attributes to describe data. For example, both the font name and the font size are attributes that describe a range of text. You use attribute groups to handle multiple attributes associated with a single data element. Figure 39 shows two examples of attribute groups.
Within a group, no two attributes have the same name. Thus groups may be thought of as sets of named values.
To access an attribute in a group, you query the group by passing an attribute that has the desired name. If the group contains an attribute with that name, that attribute is returned. Then you can coerce the returned attribute to the proper class; this is because an attribute of a given name always has a given class. Finally, you call member functions specific to that class to access the attribute's data.
Internal attributes are managed by a special class that do not need to be accessed directly. This class ensures that there is only a single internal attribute with a given name and value.
Because attributes are immutable, even shared attributes have value semantics. Each instance of a shared attribute behaves as though it is unique. Simple groups own their attributes and therefore also have value semantics. Modifications to a group do not affect other groups.
GroupHandles, as the name implies, explicitly share their underlying groups and therefore have pointer semantics. When you copy and modify a GroupHandle, other GroupHandles might be affected because change information is propagated to handles.
You can organize groups in a hierarchy, providing for dynamic inheritance of attributes from parent groups. In the CommonPoint application system, this is provided by inherited internal groups and inherited group handles. This feature allows you to query a group for an attribute, and if it is not found automatically, query its parent group, and so on recursively until the attribute is found or it is determined that a group has no parent.
Child groups can override inherited attributes simply by adding an attribute with the same name. The parent of a group can change at any time.
Because internal attribute groups can be changed, the attributes subsystem provides a notification service to inform the group's handles whenever a change occurs. This is not necessary for shared attributes because, by definition, attributes do not change. The attributes notification service informs handles not only of changes to a single internal attribute group, but of changes to its ancestor groups, as well as of changes to the group hierarchy itself.
NOTE
The attributes subsystem notification facility is a unique and custom service and is not related to the Notification framework.
Figure 43
Attributes can be
grouped
Attributes are
immutable, groups
are not
Once created, attributes are immutable; that is, they cannot be changed. However, you can change attribute groups by adding and removing attributes or by changing their inheritance hierarchy. Figure 40 shows how an attribute group is updated given that attributes are immutable. In this example, the existing attribute group contains a size attribute of 12. To change the size to 14, you create a new size attribute and add it to the group, effectively discarding the old size attribute of 12.
Attributes can
share data
You can share groups
Attributes and groups
have value semantics, GroupHandles have reference semantics
Group attributes
may be dynamically
inherited from
other groups
Group changes
provide notification
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Generated with WebMaker