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ÊÇÒ»¸öÕûÊý£¬ÎÒÃDZØÐë±à¼­´ËÊôÐÔ£¬¿ÉÒÔÓм¸ÖÖ·½·¨£ºÔÚä¯ÀÀÆ÷ÉÏË«»÷ÊôÐÔ;»òÕßÔÚä¯ÀÀÆ÷µ÷ÓôËÊôÐԵĹØÁª²Ëµ¥£¬Ñ¡Ôñ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 [Ìæ»»ºóµÄ½á¹û]֮ǰµÄÎı¾ÔòÊDz»¿ÉÐ޸쬴ËÎı¾ÓÉ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 , µ«ÔÚÀàͼÖС®_¡¯ÊDz»Ì«ÃÀµÄ£¬½ÏºÃµÄ·½·¨ÊÇÔÚ$(name)֮ǰ¼ÓÉÏ¡®_¡¯£º

- 24 -