Naming convention for UML

2019-04-06 18:08发布

问题:

Is there any name convention for UML?

I am interested in knowing how to name classes, packages and methods. However, if there is some document which specifies all naming convention for each UML diagram, please share it.

回答1:

The UML standard does not specify any naming convention. The naming standard you choose depends on the target audience of your UML model. This audience again is dependend on the purpose of your model. If you intend e.g. to generate code from your model than you need to have a result that will fit your target platform. My own experience is that choosing a platform independent naming is helpful if you would like to keep your model even after changing the target platform or if you intend to generate code for multiple target platforms. E.g. if you intend to create Java Code, DDL statements for your SQL database and XSD schema definitions for your Restful services than you have three different targets where you need a common language for all three targets. A good approach is IMHO to use platform independent type systems like CORBA IDL, XSD types or even ISO types. You could also use natural language type descriptions like "date", "time", "number", "currency". For the names of your Domain specific content you can use a mapping. E.g. if you name a Class "Customer Contact" and and operation "Call Customer", an Attribute "Customer's Name" then the mapping will allow to create e.g. Customer_Contact as the Java Class Name "callCustomer" as the operation Name and "customersName" as the attribute Name.

Whether you can apply mappings depends on the toolchain you are using. If you can't use mapping you'll have to decide which is least common denominator of your target platforms. If there is none you'll have to decide where it is the least effort to not follow the naming conventions.

Most important is IMHO whether the rules for mapping model elements to other artifacts are stricly followed and systematic (may be even automated) or whether the model is used for illustrative purposes and the mapping rules are just applied by people involved using their brains.



回答2:

Use different naming conventions based on different implementation targets. Here are a few:

  • General Naming Conventions

  • Underscore vs Mixed Case Naming Conventions

  • Leszynski Naming Conventions

  • ActionScript Naming Conventions

  • jQuery Naming Conventions

  • MXML Naming Conventions

Protocols which are implemented in many languages are also good examples:

  • bittorrent
  • libcurl
  • libusb
  • libgit
  • libexpect
  • xmpp
  • Test Anything Protocol (tap)
  • irc
  • webdriver
  • majordomo
  • websocket
  • memcached
  • Swagger
  • XDG


回答3:

Your UML naming conventions should be based on the naming conventions of the language you're programming in. You're describing your actual classes, packages, and methods so use the same names you are going to or have already used in your code.



回答4:

As already stated by Wolfgang Fahl, UML does not specify any naming conventions. However, a few months back we published a set of naming guidelines for the UML that are platform independent and domain-centered. Even though this answer comes a bit too late, you (and others) may find them quite useful: http://dx.doi.org/10.1016/j.datak.2013.09.001 and http://mpi.upc.edu/gmc-en/methods-best-practices-and-profiles/naming-guidelines-for-uml-ocl