- Does UML provide its own data types for the attributes in the class diagram?
- If so, what data types does UML provide?
- If UML provides its own data type and the target language has an equivalent type with a different name, which one do I pick for the class diagram?
- My UML book uses the lower case camel syntax for attributes names, is this a recommendation or mandatory (some languages like python, prefer a different syntax, like “date_of_birth”)?
Does UML provide its own data types for the attributes in the class diagram?
You are expected to define your own types. However, UML tries to define itself and therefore needs a couple of primitive types. All other types are derived from that.
If so, what data types does UML provide?
UML defines the primitive types Integer
, Boolean
, String
, UnlimitedNatural
, and Real
in Chapter 21 of the specification. See also Chapter 8 for values in UML, and Section 8.1 for literals in UML. For example, UML needs these primitive types so that we can have a notation for multiplicity.
If UML provides its own data type and the target language has an equivalent type with a different name, which one do I pick for the class diagram?
Some people use UML as a self-contained and language-independent programming languages. I consider this to be pointless self-flagellation.
Instead, UML models should be used to illustrate some properties of some system. The closer the model is to the system, the better. We can therefore leave the UML primitive types to the UML standard, and use whatever our actual language defines instead.
My UML book uses the lower case camel syntax for attributes names, is this a recommendation or mandatory (some languages like Python prefer a different syntax, like “date_of_birth”)?
UML does not exclusively use camel case. The specification also contains notations like A_default_templateParameter
for associations.
Again, you’re probably not using UML as a complete language in itself, but as a model for software in some other language. If you want to keep the model as close to the system being modelled, then you should also borrow the notation conventions from the actual language.
Summary
UML starts being useful when you can draw diagrams that communicate more clearly than a textual description. The standard provides a basic (visual) language that should be stuck to rather than inventing your own dialect, but you don’t have to use UML as a complete language of its own. Names and types are important properties of the subject system, so take them directly from the subject system instead of trying to awkwardly fit them into the UML meta-model.
References
Version 2.5 of the UML standard