# 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 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 (#), private (-) or package (~). The protected and package visibilities are translated in private in Idl. The package visibility is translated in private in C++. 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. The button type shows a menu proposing :

- if the current type of the attribute is a class : to select this class in the browser

- if the attribute is not read-only and if a class is selected in the browser : to set the type to be this class

- if the view containing the class containing the attribute is not read-only : to create a new class and to set the attribute type to it

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

- to set the stereotype to vector and the multiplicity to *

- but the right way here is to use a relation with the stereotype vector and the multiplicity * because Stop is a class

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 (static) 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 dialog. 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, it is visible only when C++ is set through the menu Languages

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)

${stereotype} is replaced by the translation in C++ of the attribute's stereotype (see the UML tab)

${multiplicity} is replaced by the multiplicity of the attribute (see the UML tab), must be used in case the multiplicity is a vector or array dimensioning ([ and ] are added when they are not present).

${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, it is visible only when Java is set through the menu Languages

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 type of the attribute (see the UML tab)

${stereotype} is replaced by the translation in Java of the attribute's stereotype (see the UML tab)

${multiplicity} is replaced by the multiplicity of the attribute (see the UML tab), must be used in case the multiplicity is a vector or array dimensioning ([ and ] are added when they are not present).

${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

${@} produces the annotations, when it is present in the definition the button Edit annotation is active, a specific dialog allows you to enter the annotations proposing the default annotations (Deprecated ...) and the ones defined through the classes stereotyped @interface :

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

#### Attribute dialog, tab Php

This tab allows to give the Php definition of the attribute, it is visible only when Php is set through the menu Languages

For a standard attribute :

For an enumeration's item (of course in the generated code ... is replaced by the rank of the item in the enum) :

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 Php (supposing you do not modify the Php code generator !).

When you push the button default declaration, the form specified through the generation settings depending on the stereotype and multiplicity (and of course the language !) 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 Php, empties the declaration manually or using the button not generated in Php.

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, to not generate the visibility set it to package

${static} produce an empty string when the attribute is not an 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

${var} produce var when the attribute is not read only nor static(see the UML tab) and the visibility is not package, else produce an empty string

${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)

The forms @{property} are replaced by the value of the corresponding user property if it is defined for the class or at an upper level, else it is not substituted.

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

#### Attribute dialog, tab Python

This tab allows to give the Python definition of the attribute, it is visible only when Python is set through the menu Languages

For a standard attribute without multiplicity or with the multiplicity 1 :

For a standard attribute with a multiplicity not equal to 1 :

For an enumeration's item (of course in the generated code ... is replaced by the rank of the item in the enum) :

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 Python (supposing you do not modify the Python code generator !).

When you push the button default declaration, the form specified through the generation settings depending on the stereotype and multiplicity (and of course the language !) 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 Python, empties the declaration manually or using the button not generated in Python.

The instance attributes are automatically produced at the beginning of the body of the operation __init__ (this operation is produced for each class even when you don't define it). The static attributes are produced inside the class definition.

${comment} produces a comment from the UML description, adding a # at the beginning or each line, following the current indent. A newline is produced if needed at the end to not have something else generated on the same line after the comment.

${description} is like for ${comment} but without adding #.

${self} inside the operation __init__ this produces the name of the first parameter followed by a dot, else nothing.

${type} produces the type of the attribute, probably used inside a comment, may be for a form @var

${multiplicity} produces the multiplicity of the attribute, probably used inside a comment

${stereotype} is replaced by the translation in Python of the attribute's stereotype (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) if it is not empty, else None

The forms @{property} are replaced by the value of the corresponding user property if it is defined for the class or at an upper level, else it is not substituted.

Refer to the generation settings and Python 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, it is visible only when Idl is set through the menu Languages

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 type of the attribute (see the UML tab)

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

${stereotype} is replaced by the translation in Idl of the attribute's stereotype (see the UML tab)

${multiplicity} is replaced by the multiplicity of the attribute (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;
    }

Php
    final public function getName()
    {
      return $this->name;
    }

    public function setName($value)
    {
      $this->name = $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 (except Php and Python) :

As usual the last column do allows to copy/past/cut/insert line and applies on the line where you did the mouse click.

The third C++ tab allows to set the default definition of an attribute in C++, only visible when C++ is set through the menu Languages :

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++, only visible when C++ is set through the menu Languages :

The second Java tab allows to set the default definition of an attribute in Java, only visible when Java is set through the menu Languages :

The third Java tab allows to set the default definition of an enumeration's item in Java, to set the get and set operations specificities in Java, only visible when Java is set through the menu Languages :

The second Php tab allows to set the default definition of an attribute, to set the default definition of an enumeration's item, and to set the get and set operations specificities in Php, only visible when Php is set through the menu Languages :

The first Python tab allows to set the default attribute definition for Python depending on the multiplicity, only visible when Python is set through the menu Languages :

The second Python tab allows to set the default enum item definition for Python and the get and set specificities for Idl, only visible when Python is set through the menu Languages :

The second Idl tab allows to set the default attribute definition for Idl, only visible when Idl is set through the menu Languages :

The third Idl tab allows to set the default definition of an attribute in a union, the enumeration item default definition and the get and set specificities for Idl, only visible when Idl is set through the menu Languages :

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, the full member definitions and the visibility are shown) :

The way an attribute is written or not in its class picture depend on the class drawing settings, drawing language, hide attributes, show member visibility, show attribute multiplicity, show attribute initialization, member max width 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:

Changing the drawing language to Php :

Changing the drawing language to Python :

Previous : relation

Next : operation