Defining attribute features

When you click the Invoke Feature dialog button or double-click an attribute, the Attribute window opens. This window is also displayed when you select an attribute from the browser or from the appropriate compartment in a diagram.

About this task

On the General tab, you define the general features for an attribute through the various controls on the tab.

  • In the Name field you specify the name of the attribute. The default name is attribute_n, where n is an incremental integer starting with 0. To enter a detailed description of the attribute, use the Description tab.
  • You use the L button to open the Name and Label window to specify the label for the element, if any.
  • In the Stereotype list you specify the stereotype of the attribute, if any.
    • To select from a list of current stereotypes in the project, click the Select Stereotype button Select Stereotype button.
    • To sort the order of the selected stereotypes, click the Change Stereotype Order button Change Stereotype Order button.
      Note: The COM stereotypes are constructive; that is, they affect code generation.
  • In the Attribute type area you specify the attribute type. There are two ways to specify the type:
    • Select the Use existing type checkbox to select a predefined or user-defined type or class. Use the Type list to select from among the Rhapsody® predefined types, and any types and classes you have created in this project. Or to define a new type, delete the value in the Type list box to enable the Invoke Feature Dialog button Invoke Feature Dialog button and click it to open the Type window.
    • Clear the Use existing type check box if there is no defined type. A C++[Java] Declaration box displays in which you can give the attribute a declaration appropriate for your language edition.
    Note:

    When you create a new attribute, variable, or argument, the Type field is set to int by default. If you want to use a different default type, you can use the property General::Model::DefaultType to specify the type. The value of the property must use the format package::type, for example TypePackage::int32.

    If you want elements to be marked Untyped until someone specifically selects a type, set the value of the DefaultType property to "Untyped".

  • In the Visibility area you specify the type of access (visibility) for the accessor/mutator generated for the attribute: Public, Protected, or Private.

    When you generate code, each attribute is generated into three entities:
    • The data member itself
    • An accessor (get) method for retrieving the data value
    • A mutator (set) method for setting the data value
      Note: The visibility setting affects only the visibility of the accessor and mutator methods, not of the data member itself. The data member is always protected, regardless of the access setting.
  • In the Multiplicity field (displayed when appropriate) you specify the multiplicity of the attribute. If this number is greater than 1, use the Ordered checkbox to specify whether the order of the reference type items is significant. The modifier choices are as follows:
    • Constant specifies whether the attribute is read-only (checkbox is selected) or modifiable (checkbox is cleared).
    • Reference specifies whether the attribute is referenced as a reference, such as a pointer (*) or an address (&) in C++.
    • Static creates a static attribute, which belongs to the class as a whole rather than to individual objects.
    Note: From IBM® Engineering Systems Design Rhapsody 10 onwards, the const keyword is now placed before the variable name in the generated code.

    For example, int const Number;

    In the previous IBM Engineering Systems Design Rhapsody versions, the const keyword was placed before the data type of the variable in the constant attribute or variable declaration.

    For example, const int Number;

    The position of const in declaration of constant attribute or variable can be changed by using following WriterTemplate properties:

    • For Attribute:
      • [Lang]_CG::WriterTemplates::AttributeImp
      • [Lang]_CG::WriterTemplates::AttributeSpec
    • For Variable:
      • [Lang]_CG::WriterTemplates::GlobalAttributeImp
      • [Lang]_CG::WriterTemplates::GlobalAttributeSpec

    For more information about WriterTemplate, see Further customization of code formatting

    The setting for compatibility with earlier versions that is CGCompatibilityPre100Cpp/CGCompatibilityPre100C, is loaded automatically if it is an old model. When the setting for compatibility with earlier versions is loaded into the model, then the generated code is same as before.

  • In the Initial Value box you specify the initial value for the attribute.
If you select the Static checkbox on the Features window for an attribute, use the Initial Value field to enter an initial value.

You can open a text editor for entering initialization code by clicking the Ellipses button Ellipsis button associated with the box.