# Class

A class may contain nested classes, relations, attributes, operations , extra members and dependencies on packages. The order of the class's sub-items is very important because it is followed by the C++/Java/Php/python/Idl generators.

The representation of a class in the browser indicates if the class is abstract or is a template class, furthermore a nested class icon has a reduced size :

A class is the support to define all kinds of class depending on the languages, the stereotype specify what a class is. The way a stereotype is translated for each language is configured and is specified through the generation settings. You can set a default list of stereotypes for the classes and their relations through the edit default stereotype entry of the project's menu.

Some stereotypes have a special meaning for BOUML :

- typedef : a class having this stereotype may have an associated base type used to construct the typedef. It is not possible to add a relation/attribute/operation to a class stereotyped typedef, nor to define it as a template (but it may instantiate a template). This stereotype doesn't have sense in Java.

- enum : a class having this stereotype is an enum, need at least the JDK 5 in Java. Because a Java JDK 5 enum may have attributes, relations and operations, it is possible to add these kinds of members to a class having the stereotype enum, but their default definitions are empty in C++ and Idl. it is not possible to define or instantiate a template,they are not yet managed in Java. In Php an enum produces a class having only const variables

- enum_pattern : a class having this stereotype is an enum even in Java for which a special definition compatible with JDK release less than 5 is produced. it is not possible to add a relation/operation to a class stereotyped enum nor to define or instantiate a template.

- union : a class having this stereotype cannot instantiate a template

- actor : just to change the representation, not relevant for the code generators

- stereotype : indicate the class support a stereotype part of a profile, refer to the chapter describing the profiles.

- metaclass : indicate the class is a meta class, refer to the chapter describing the profiles.

Obviously because you may change the stereotype at any time, it is possible to define for instance a class with an operation and after that to change its stereotype to enum_pattern ... In this case BOUML does nothing, for instance it does not delete itself the operation to help you to come back to a more appropriate stereotype without undesirable modifications.

The extend of the previous stereotypes include C++ and Java and Idl both. This means for instance that you cannot add an operation to an enum_pattern independently of the translation of this stereotype in C++/Java/Php/Python/Idl specified through the generation settings. But it is also possible to have stereotypes with an extend limited to each language through the definition of new stereotypes. For instance, if you define the stereotype eiu which is translated by enum in C++, interface in Java, class in Php and Python and union in IDL through the generation settings, you will have exactly that you want : magic ! isn't it ?

The stereotypes known at each language level by BOUML are :

- C++ : class (or empty stereotype), enum, struct, typedef and union

- Java : class (or empty stereotype), enum, enum_pattern, interface and @interface

- Php : class (or empty stereotype), enum, interface

- Python : class (or empty stereotype), enum (produce also a class)

- Idl : enum, exception, interface, struct, typedef, union and valuetype

The class's properties will be exposed below.

## Menus

The class menu appearing with a right mouse click on its representation in the browser depend on the stereotype and the artifact association, it is something like these, supposing the class not read-only nor deleted (see also menu in a diagram) :

### Menu : add ...

The first entries of the menu allowing to add something may not be present depending of the class's stereotype.

### Menu : edit

edit allows to show/modify the class properties. In case the class is read-only, the fields of the dialog are also read-only. Note that for consistency purpose you cannot edit a class while any other edition is made, and while a class is edited all the other editions are impossible.

#### Class dialog, tab Uml

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

The proposed stereotypes are the default one 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.

abstract allows to declare that the class is an abstract class (not instanciable).

The artifact used to produce the class source code must be chosen in the proposed list or the field may be empty. Obviously a nested class can't have an associated artifact, but a nested class has a visibility.

The description will be generated in the class source code (in case the ${comment} or ${description} macro appears in the class definition) as a comment.

The editor button visible above and associated here to the description, allows to edit the description 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.

#### Class dialog, tab Parametrized

The parametrized tab allows to specify the formals of a template / generic class.

For instance with :

if the class have the default proposed class definition, the C++ class definition (named Dict) is :

    template<class V, class K = string> class Dict ...

#### Class dialog, tab Instantiate

The instantiate tab allows to specify the actual of a class inheriting templates classes. It appears only when the edited class inherits or realizes at least a template class. Obviously, a template class may inherit another ones.

For instance with this definition of Dict :

if the class have the default proposed class definition, the C++ class definition of theredheaded is :

    class theredheaded : public Dict<string, string> ...

the Java class definition is :

    class theredheaded extends Dict<String, String> ...

When the class theredheaded is edited only the actuals are editable in the tab Instantiate, both for C++ and Java.

Supposing you have a template class vector and you want to define a vector or boolean, obviously the right definition is not :

    class vectorOfBoolean : public vector<bool> {...}

the right definition is :

    template<> class vector<bool> {...}

To do this you just have to define the class named vector<bool>

#### Class dialog, tab C++

This tab allows to give the C++ definition of the class, it is visible only when C++ is set through the Languages menu.

Template definition :

Template instantiation (of course a class may be both a template definition and a template instantiation) :

Enum (class with the stereotype enum or enum_pattern) :

Standard class :

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 depending on the class stereotype (and of course the language !) is proposed, this last may be modified as you want, even to produce illegal source code. For instance if you do not want to follow the inheritance specified by the class's relations, you just have to replace ${inherit} by anything you want.

When you do not want to have this class defined in C++ (but it must be defined in Java or Idl, so the class must have an associated artifact), empties the declaration manually or using the button not generated in C++ (an other way is to empty the C++ definition of the artifact).

The external check box must be used when the class must not be defined in C++ by BOUML, but you want to specify the name of the class (to not follow the Uml/Java/Idl name) and/or the included files and/or using forms or any other forms needed to use it.

${template} produce a template declaration in case the class is a template class, else an empty string.

${members} produce the declaration and definition of the class members (relations, attributes, operations and extra members) following the browser order and repartition in the header and source files.

${inline} produce the definition of the operations and extra members declared inline, may be an empty string.

Refer to the generation settings for more details.

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.

#### Class dialog, tab Java

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

Generic definition :

Generic instantiation :

For a JDK 5 enum (class with the stereotype enum) :

For a class with the Java stereotype enum_pattern :

Standard class :

${public} produce an empty string when the check box public is not checked, else produce public (!)

${final} produce an empty string when the check box final is not checked, else produce final (!!)

The external check box must be used when the class must not be defined in Java by BOUML, but you want to specify the name of the class (to not follow the Uml/C++/Idl name).

${members} produce the declaration of the class members (relations, attributes, operations and extra members) following the browser order, doesn't produce the enumeration items of an enum. In an enum, an attribute is not an enumeration item when its stereotype is attribute.

${items} produces the enumeration items of an enum. an attribute is an enumeration item when its stereotype is not attribute.

${extend} is replaced by the class inheritance

${implement} is replaced by the interface inheritance

${@} 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 :

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.

#### Class dialog, tab Php

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

For an enum (class with the stereotype enum) :

Standard class :

${visibility} produce an empty string when the visibility except if this one is package. If you want to generate Php 4, set the visibility to package

${final} produce an empty string when the check box final is not checked, else produce final (!!)

${abstract} produce an empty string when the check box abstract is not checked, else produce abstract (!!)

The external check box must be used when the class must not be defined in Php by BOUML, but you want to specify the name of the class (to not follow the Uml/C++/Php/Python/Idl name).

${members} produce the declaration of the class members (relations, attributes, operations and extra members) following the browser order

${items} produces the enumeration items of an enum. other members are not produced

${extend} is replaced by the class inheritance

${implement} is replaced by the interface inheritance

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.

#### Class dialog, tab Python

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

For an enum (class with the stereotype enum), recall the instance attributes are produced in the operation __init__ :

Standard class :

The Python 2.2 check box allows to ask for classes introduced by Python 2.2, the default value of this toggle is the one specified by the generation settings

The external check box must be used when the class must not be defined in Python by BOUML, but you want to specify the name of the class (to not follow the Uml/C++/Php/Python/Idl name) on the first line (${name} by default), may be followed by import forms whose will be produced by the code generator.

${members} produce the declaration of the class members (relations, attributes, operations, extra members and sub classes) following the browser order. Note that the instance attributes are produced at the beginning of the body of the operation __init__.

${inherit} is replaced by the inheritance, a class without inheritance inherits of object if the toggle Python 2.2 is set

${docstring} is replaced by the description of the class placed between ””” and followed by a newline. If the description is empty nothing is produced. You can replace it by ${comment} or ${description} if you prefer.

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.

#### Class dialog, tab Idl

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

${local} produce an empty string when the check box local is not checked, else produce local (!!), this one is only available when the stereotype of the class is interface in Idl (see generation settings).

${custom} produce an empty string when the check box custom is not checked, else produce custom (!), custom is available when the stereotype of the class is valuetype in Idl (see generation settings).

The external check box must be used when the class must not be defined in Idl by BOUML, but you want to specify the name of the class (to not follow the Uml/C++/Java name) and/or the included files needed to use it. Not yet implemented in the Idl generator.

${members} produce the declaration of the class members (relations, attributes, operations and extra members) following the browser order.

Refer to the generation settings for more details.

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.

### Menu : duplicate

The menu entry duplicate clone the class and all its children, including the nested classes.

The self relations (a self relation is a relation between a class and itself) are specially managed : they became a self relation to the clone.

For instance, if the initial situation is the following :

After the duplication of C1 into the new class C3 :

Note that the duplication of the relation c1 of C3::SC is still a relation to C1, because only the self relation are specially managed, not all the relation to the duplicated class (the context of the inner class(es) SC is visible thanks to the drawing setting “show context” and also to the inner class relation).

### Menu : create source artifact

The menu entry create source artifact is present when the class does not have an associated artifact, but the class view containing the class have an associated deployment view. Choosing this entry a new artifact having the name of the current class and the stereotype source is created in the deployment view associated to the class view containing the current class.

To quickly create is needed the associated deployment view and associate an artifact to all the classes of a class view use the plug-out deploy.

### Menu : select associated artifact

This menu entry is present when the class have an associated artifact, to quickly select this one, the current class may also be quickly selected from its associated artifact.

### Menu : select associated component

### Menu : select an associated component

This menu entry is present when the class have an associated component(s), to quickly select this one, the current class may also be quickly selected from its associated component.

### Menu : referenced by

To know who reference the current class

### Menu : mark

See mark

### Menu : delete

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

Delete the class and all its children, 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 : generate

To generate source code for the languages for whose the class and the associated artifact have a definition.

### Menu : tool

The menu entry tool is only present in case at least a plug-out may be applied on a class. The selected tool is called and applied on the current class.

## Default stereotypes

The dialog allowing to set the default stereotypes has a tab reserved for the classes :

As you can see, it is possible to set a default stereotypes list for the classes and all the relations between classes.

The code generators does not distinguish the generalization and the realization, even they do not have the same meaning in UML.

## Generation settings

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

The tabs associated to a given language are only visible when the corresponding language is set through the Languages menu.

The tab Stereotypes allows to specify how the class's stereotypes are translated in each language :

The second C++ tab allows to define the default C++ class definition depending on the stereotype :

The first Java tab allows to define the default Java class definition depending on the stereotype :

The first Php tab allows to define the default Php class definition depending on the stereotype :

The first Python tab allows to define the default Python class definition depending on the stereotype, and to use Python 2.2 classes or not by default :

The first Idl tab allows to define the default Idl class definition depending on the stereotype :

The tab Description allows to set a default description (the default description is used when you hit the button default in the description part of a class of the class dialog) :

## Drawing

A class is drawn in a diagram as a rectangle or an icon depending on the class's stereotype and the drawing settings :

If the class is stereotyped by a stereotype part of a profile and this stereotype has an associated icon, this icon will be used when the drawing mode is natural, the image is unchanged when the scale is 100% else it is resized.

A right mouse click on a class in a diagram calls the following menu (supposing the class editable) :

### Menu : edit drawing settings

These drawing settings concerns only the picture for which the menu is called.

A settings valuing default indicates that the setting specified in the upper level (here the diagram) must be followed, obviously this one may also be default ... up to the project level. When you add a class in a diagram, all the settings are set to default.

#### drawing language :

Allows to choose how the operations and attributes of the class must be written in case show full members definition is true (at the class level or an upper level), this may hide an operation or an attribute when it is not defined for the chosen language.

For instance, the class C has the attribute a having the type uchar (supposed translated unsigned char in C++, char in Java and octet in Idl), the operation op returning an uchar and having the input parameter p having the type uchar and only in Idl a second out parameter p2 of the same type. The C picture is, depending on the drawing language :

#### drawing mode :

Allows to draw the class using a rectangle or an icon :

- class : to draw a rectangle whatever the stereotype of the class

- control : to draw the control icon whatever the stereotype of the class

- boundary : to draw the boundary icon whatever the stereotype of the class

- entity : to draw the entity icon whatever the stereotype of the class

- actor : to an actor whatever the stereotype of the class

- natural : the draw the class depending on its the stereotype

#### show context :

To indicate if the context where the class is defined must be written, and if yes, how. The context may be the "UML context" which is the path of the class in the browser, or the C++ namespace, or the Java package or at least the Idl module. In case the class has an associated artifact, the namespace/package/module is the one specified by the package containing the artifact, else by the package containing the class itself. Obviously nothing is written in case the namespace/package/module is not specified.

For instance, the package Package2 specify the C++ namespace nsp, the Java package jpck, the python package ppck and the Idl module mdl. The C picture is, depending on the show context :

| UML | C++ namespace | Java package | Python package | Idl module

#### hide attributes :

To hide or not the attributes, it is also possible to specify the visibility for each one.

#### hide operations :

To hide or not the operations, it is also possible to specify the visibility for each one.

#### show full members definition :

To write all the attribute/operation definitions, or just their names. See also drawing language.

#### show members visibility :

To write or not the visibility

#### show attributes multiplicity :

To write or not the multiplicity of the attributes when the drawing language is UML and you ask to show for full members definition

#### show attributes initialization :

To write or not the default value of the attributes when you ask to show for full members definition

#### show attributes modifiers :

To write or not the modifiers when you ask to show for full members definition, except for the / indicating the attribute is derived which is writtent even you don't ask for the full members definition

#### member max width :

To limit the width (in characters) used to produce the definition of the operations and attributes. When the width is greater that the max width, the string is cut and ... is added. Doesn't take into account the stereotype.

#### show parameter direction :

To write or not the direction of the operation's parameters

#### show parameter name :

To write or not the name of the operation's parameters

#### show information note :

To show or not the constraints as a note. This note is able to contain the constraints of the class itself, the constraints of its members and the inherited constraints. To choose which constraint must be written, edit the node and a dedicated dialog will appears :

#### show stereotype properties :

to indicate through a note the (non empty) value of the stereotype properties in case the class is stereotyped by a stereotype part of a profile. By default the stereotype properties are hidden.

#### class color :

To specify the fill color.

### Menu : individual attribute visibility :

To specify the hidden / written attributes of the class through the following dialog :

If you set specify visible members rather than hidden ones, when you will add new attributes these ones will not be added in the class picture.

### Menu : individual operation visibility :

To specify the hidden / written operations of the class through the following dialog :

If you set specify visible members rather than hidden ones, when you will add new operations these ones will not be added in the class picture.

### Menu : set associated diagram

set associated diagram allows to automatically open the current diagram when a double mouse click is made on the class representation in a diagram or the browser. After that the only way to edit the class is to choose the edit entry in the menu.

### Menu tools :

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

Previous : use case

Next : relation