how to write data attributes in UML with typedef u

2019-09-06 09:21发布

问题:

this is my sample code my question is how am i going to write uint delay in UML Class Diagram, because it is typedef unsigned -----------------------------------------------------------------------------------------should i write it like this? - delay : int or this way? - delay : uint ---------------------------------------

typedef unsigned int uint; 

class MyBreakoutGameType : ...
{
public:

private:
     uint delay;
};

回答1:

Your diagram for the mentioned code should look like



回答2:

Version 13.5 of Enterprise Architect does import typedefs as classes with «typedef» stereotype. The original type is then referred to by generalization. This way the information of the underlying type does not get lost.

In case the «typedef» stereotype is undefined (and shall not be added to the used profile) you may use an ordinary class which has an «import» relation to the original type.

This answer suggests to use only the «import» relation specifying the name of the alias on the connector. I do not prefer that solution as the alias can then not be referred to.



回答3:

UML has a few predefined primitive types, e.g. "Integer", but "int" is not a predefined primitive type in UML. New primitive types can be modeled using a classifier with the «primitive» keyword (UML 2.5 spec, section 10.2.5). To specify the corresponding C++ data type, you may wish to add a note:

Then, you may using this primitive data type as the data type of an attribute, like this:

Of course, this makes the class dependant on the existence of the «primitive» uint. You may stress this dependency by drawing a dashed arrow from MyBreakoutGameType to uint, but this is optional.