Command \umlclass#

You can define a class with the \umlclass command:

\umlclass{namespace::A}{
  + n : uint \\
  \umlstatic{-- i : int} \\
  \# r : const float
  }{
  + setA(i : int) : void \\
  \umlvirt{\# getA() : A}
}

Figure made with TikZ

Figure made with TikZ

\umlclass takes 3 arguments:

  • The class name, that can contains double dots.

  • The class attributes. Each attribute is written according to the usual UML format: visibility name : type. The visibility is either + for public attributes, --``for private attributes, and ``# for protected attributes. Attributes information are separated by \\.

  • The class member functions. Each member function is written according to the usual format: visibility name(arg1 : type, arg2 : type, ...) : type.

See also

Static attributes or member functions can be defined as argument of the umlstatic command.

See also

Virtual member functions can be defined as argument of the umlvirt command.

For empty classes (that contains no attributes and no operations), you can use a shortcut command \umlemptyclass:

\umlemptyclass{namespace::class-name}

Figure made with TikZ

Figure made with TikZ

You may also prefer drawing a single rectangle node instead of a 3 parts rectangle node. In this case, you may use the simple option of \umlclass or the shortcut command \umlsimpleclass that also takes only the class name for argument and the same options as the command \umlclass:

\umlsimpleclass{namespace::class-name}

Figure made with TikZ

Figure made with TikZ

There are different types of classes: class, abstract, interface, typedef, enum. You can specify it with the type option (the default value is class):

\umlemptyclass[type=interface]{class-name}

Figure made with TikZ

Figure made with TikZ

See also

The type is written between \(\ll\) and \(\gg\) above the class name, excepted the class type (default behavior), and the abstract type, where the class name is written in italic style instead:

\umlemptyclass[type=abstract]{class-name}

Figure made with TikZ

Figure made with TikZ

See also

Shortcuts exist for each value of the type option: \umlabstract, \umltypedef, \umlenum, \umlinterface. For these shortcuts, option type is forbidden.

See also

You can also draw interfaces with a circular node. To do so, you can use the simple option to the \umlinterface command, or use the shortcut \umlsimpleinterface

\umlsimpleinterface[x=0, y=0]{I}

Figure made with TikZ

Figure made with TikZ