uml建模工具中bouml的使用(整理版,中英文对照) 下载本文

Add attribute and operation增加属性和操作 We want to define an attribute named att, and an operation named oper. Call the class menu doing a left mouse click on the class in the diagram or in the browser, choose add attribute then add operation. When you add the members through the diagram their editor are automatically called, not through the browser. The class members are visible in the browser and the class picture :

我们想定义一个命为att的属性和一个命为oper的操作。从类的关联菜单上选择执行add attribute,然后选择执行add operation 。当你通过图增加类的成员时,调用相关的编辑器,而不是浏览器。类的成员可见,类的图像如是

- 21 -

Because of the default visibility set through the class settings the attribute is protected and the class is public. The class settings may be set at the class view or package levels, following the same principles of the drawing settings.

因为默认的可见性由class settings 设置(属性为保护的而类是公开的)。而class settings 而在类视图级或包级别进行设置,遵循和drawing settings 同样的原则。

Edit attribute编辑属性 One decide that att must be an int, we have to edit it, this may be done through several ways : double click on it in the browser, to call its menu on the browser and choose edit, ot to call the menu of its class in the diagram choosing edit attribute then att. You obtain the dialog :

一旦决定att是一个整数,我们必须编辑此属性,可以有几种方法:在浏览器上双击属性;或者在浏览器调用此属性的关联菜单,选择edit项; 或在图上调用此属性的类的关联菜单,选edit attribute,再选择att , 你将看到一对话框:

- 22 -

The first tab concern the UML characteristics, by default an attribute is an instance member (not a class member), is not volatile and is not read-only. Each other tab is link to a specific language : with BOUML you may design in several languages at the same time. For instance the HTML generator implementation is done in C++ and Java both.

第一个标签关心的是UML特征,一个属性默认为一个示例的成员(不是类的成员),不是易变的(volatile),也不是只读的(read-only)。其它的每一个标签连接到一个特定语言:使用bouml,你可以同时使用几种语言进行设计。例如HTML生成器是由C++和Java两者来实现的。

Set the type to int, choosing among the predefined types list (modifiable through the generation settings) or typing int.

设置其类型为int ,通过从先前定义好的类型列表(通过generation settings可修改)中选择一个,或直接输入int。

Go in the C++ tab (clicking on C++) :

转到C++标签 (在C++上点击):

- 23 -

As you can see, the visibility for C++ is the UML one by default, but this is not mandatory to allow to help to not have the same visibility for instance in C++ and Java, and in C++ an attribute may be mutable.

正如你所见,C++的可见性默认是遵循UML的一个值,但这不强制性的,有助于那些具有不相同的可见性的情形(C++和Java),并且C++里属性可能是mutable。

The text behind declaration is editable, not the one behind result after substitution which shows the source code as it will be generated by the C++ generator (supposing you don't modify it !). 在declaration 之前的文本是可修改的,而在result after substitution [替换后的结果]之前的文本则是不可修改,此文本由C++的生成器产生的源代码(假定你不修改它!)。

Except for the keywords signaled by ${} and the user properties signaled by @{} all the other characters are generated unchanged, including the new line. It is not difficult to understand that ${type} is replaced by int and ${name} by att, both set in the UML tab. This also means that if you replace ${type} by aze the generated type for att in C++ will be aze, etc ...

除了由$()标记的关键字和由@()标记的用户的特性(用户属性名-值对集合)外,所有其它的字符将按原样生成,包括新行。$(type) 将由 int 替换而@(name) 将由 att 替换,这对你来说并不难理解。此两者的设置在UML标签内进行。这也意味着,如果你用 aze 替换$(type),在C++中关于att 的生成类型将是 aze 等等。。。

Perhaps you have coding rules and for instance in C++ the name of an attribute must start by '_' ? Of course you may rename the attribute _att, but to see the '_' in the class diagram is not very pretty, it is better to add the '_' before ${name} :

也许,你有自己的编码规则,例如在C++中属性的名字必须以‘_’开头,当然你可重新为属性命名为 _att , 但在类图中‘_’是不太美的,较好的方法是在$(name)之前加上‘_’:

- 24 -