# Attribute

Contrarily to the relations, there is no restriction concerning the types of the attributes, whose may be a class or an int for instance. An attribute may have a stereotype, but it does not have a special meaning for BOUML.

An attribute is created through the class menu called from the browser or a class picture in a class diagram :

The icon in the browser indicates if an attribute is public (+), protected (#) or private (-). The protected visibility is translated in private in Idl. A class attribute is underlined. It is possible to move an attribute from a class into an other using the drag and drop or the marked items capabilities, see browser items.

In a class having the stereotype enum, the attributes are renames item in the menus.

## Menus

The attribute menu appearing with a right mouse click on its representation in the browser is something like these, supposing it is not read-only nor deleted (the second one is associated to an enumeration's item) :

### Menu : edit

edit allows to show/modify the properties of the attribute. In case the attribute is read-only, the fields of the dialog are also read-only.

#### Attribute dialog, tab Uml

The tab Uml is a global tab, independent of the language.

For a standard attribute :

For an enumeration's item :

The proposed types for a standard attribute are the non class types defined in the first tab of the generation settings, more all the classes defined in the project (with their localization to distinguish synonymous classes). You are not limited to the proposed list, and any form (even invalid for the target language(s)) may be given.

Nevertheless I strongly recommend you to not add type modifier (like *, & etc ...) with a class name in the UML tab because BOUML differentiate a reference to a class of the model and any other forms. Supposing you also have the class attribute stops defined (for C++) like this :

the C++ generated code will be the desired one, but if you rename the class Stop, the type of the attribute stops will not be updated. Furthermore the C++ code generator will not see the usage of the type Stop and will not automatically generate class declaration and #include form for it.

The good way may be to say that stops is a Stop and modify the attribute definition in C++ to have a vector (in fact for me the right way here is to use a relation with the stereotype vector and the multiplicity *).

The proposed stereotypes are the default ones specified through the Default stereotypes dialog more the current one (empty here). It is possible to choose into the list or to give a new one, or to empty it. The stereotype of an attribute does not have special meaning for BOUML.

The initial value give the default value of the generated attribute(s), in C++ it is taken into account only when the attribute is a class attribute or an enumeration item. By default the generated form is exactly the one you give, this means that you have to give the '=' when it must be generated, this allows to give the arguments of a constructor.

The visibility may be chosen with the radio buttons, the attributes have a default visibility set through the class settings :

By default the description is used to produce comments by the code generators.

The editor button visible above and associated here to the description and initial value, allows to edit the description or initial value in an other window, or to call an external editor (for instance Xcoral) specified through the environment variable BOUML_EDITOR. Note that this external editor have to create an own window, its parameter is the pathname of the file containing the description, its execution is done in parallel with BOUML which looks each second at the file contents to get the new definition until the dialog is closed (I do not like very much this polling but this works even QT isn't compiled with the thread support).

The default button visible above associated to the description allows to set the description with a default contain specified through the generation settings. Useful to generate comments compatible Java Doc or Doxygen for instance.

#### Attribute dialog, tab C++

This tab allows to give the C++ definition of the attribute.

For a standard attribute :

For an enumeration's item :

In BOUML the generated code is obtained by the substitution of macros in a text, only the Declaration part is editable, the other one help you to see what will be generated for C++ (supposing you do not modify the C++ code generator !).

When you push the button default declaration, the form specified through the generation settings is proposed, this last may be modified as you want, even to produce illegal source code.

When you do not want to have this attribute defined in C++, empties the declaration manually or using the button not generated in C++.

It is possible to follow the visibility as it is set in the UML Tab or to change it.

${static} produce an empty string when the attribute is not a class attribute (see the UML tab), else produce static

${const} produce an empty string when the attribute is not read only (see the UML tab), else produce const

${type} is replaced by the type of the attribute (see the UML tab)

${name} is replaced by the attribute's name (see the UML tab)

${value} is replaced in the source file by the initial value of the attribute (see the UML tab) when this one is not an enumeration item. For the enumeration items the value is of course generated in the header file.

${h_value} is replaced in the header file by the initial value of the attribute (see the UML tab). ${h_value} must be used when you want to set the value of a const attribute.

${mutable} produce an empty string when the check box mutable is not checked, else produce mutable

${volatile} produce an empty string when the check box volatile is not checked, else produce volatile

The definition of the attribute stops may be :

Refer to the generation settings and the C++ Generator for more details and explanation of the other keywords.

#### Attribute dialog, tab Java

This tab allows to give the Java definition of the attribute.

For a standard attribute (as you can see string is automatically translated into String thanks to the generation settings):

For an enumeration's item :

In BOUML the generated code is obtained by the substitution of macros in a text, only the Declaration part is editable, the other one help you to see what will be generated for Java (supposing you do not modify the Java code generator !).

When you push the button default declaration, the form specified through the generation settings is proposed, this last may be modified as you want, even to produce illegal source code.

When you do not want to have this attribute defined in Java, empties the declaration manually or using the button not generated in Java.

It is possible to follow the visibility as it is set in the UML Tab or to change it replacing ${visibility} by the desired one.

${static} produce an empty string when the attribute is not an class attribute (see the UML tab), else produce static

${final} produce an empty string when the attribute is not read only (see the UML tab), else produce final

${transient} produce an empty string when check box transient is not checked, else produce transient

${volatile} produce an empty string when the check box volatile is not checked, else produce volatile

${type} is replaced by the class pointed by the attribute (see the UML tab)

${name} is replaced by the attribute's name (see the UML tab)

${value} is replaced by the initial value of the attribute (see the UML tab), may be used to specify the value of an enumeration's item for instance

Refer to the generation settings and Java generator for more details and explanation of the other keywords.

#### Attribute dialog, tab Idl

This tab allows to give the Idl definition of the attribute.

For a standard attribute (here of a valuetype) :

For an enumeration's item :

In BOUML the generated code is obtained by the substitution of macros in a text, only the Declaration part is editable, the other one help you to see what will be generated for Idl (supposing you do not modify the Idl code generator !).

When you push the button default declaration, the form specified through the generation settings is proposed, this last may be modified as you want, even to produce illegal source code.

When you do not want to have this attribute defined in Idl, empties the declaration manually or using the button not generated in Idl

It is possible to follow the visibility as it is set in the UML Tab or to change it replacing ${visibility} by the desired one.

${type} is replaced by the class pointed by the attribute (see the UML tab)

${name} is replaced by the attribute's name (see the UML tab)

Refer to the generation settings and Idl generator for more details and explanation of the other keywords.

### Menu : duplicate

The menu entry duplicate clone the attribute.

### Menu : add ...

These entries allow to produce get and set operations on the attribute, contrarily to the similar operations made by hand, these two ones are linked to the associated attribute to be updated, or deleted when the attributes is deleted. The default name of the operations and their characteristics are set through the generation settings.

By default, the get and set operations generated for the Stop's attribute name are :

C++

    inline const string Stop::get_name() const {
      return name;
    }

    void Stop::set_name(string new_value) {
      name = new_value;
    }

Java

    public final String get_name() {
      return value;
    }

    public void set_name(String new_value) {
      name = new_value;
    }

Idl

    string get_name();

    void set_name(string new_value);

### Menu : delete

The menu entry delete is only present when the attribute is not read-only.

Delete the attribute, associated get and set operations when they exist, and all the representation of them in the opened diagrams. After that it is possible to undelete them (from the browser) until you close the project : obviously the deleted items are not saved !

### Menu : mark

See mark

### Menu : tool

Appears only when at least one plug-out is associated to the attributes. To apply a plug-out on the attribute.

## Default stereotypes

The dialog allowing to set the default stereotypes has a tab associated to the attributes :

The stereotype of an attribute does not have a special meaning for BOUML.

## Generation settings

This very important dialog allows to specify many default definitions concerning the attributes, more details will be given in C++ generator, Java generator and Idl generator.

The first tab allows to specify how the types not supported by an UML class are translated in each language :

The third C++ tab allows to set the default definition of an attribute in C++ :

The fourth C++ tab allows to set the default definition of an enumeration's item in C++ and to specify the get and set operations specificities in C++ :

The first Java tab allows to set the default definition of an attribute and an enumeration's item in Java :

The second Java tab allows to set the get and set operations specificities in Java :

The third Idl tab allows to set the default attribute definition and the get and set specificities for Idl :

The tab Description allows to set a default description :

## Drawing

The attributes are only drawn with their class in a class diagram (here the drawing language is UML and the full member definitions are shown) :

The way an attribute is written or not in its class picture depend on the class drawing settings, drawing language, hide attributes and show full members definition, and also on the class menu entry individual attribute visibility.

Changing the drawing language from UML (the default) to C++ or IDL :

Changing the drawing language to Java:

Previous : relation

Next : operation