Classes and Other Entities
Last updated
Was this helpful?
Last updated
Was this helpful?
Classes are the basic component of class diagrams. They describe the structure and features of the related objects on a class diagram.
Classes are declared with a class type followed by a name. The simplest class type is "class." A class name is typically capitalized in UML.
Classes have 11 properties. The only mandatory properties are type and name.
type - determines the type of class
name - name of the class
alias - gives the ability to use a variable to identify the class
generic - gives the class an optional descriptor
stereotype -applies a stereotype text to the class
spot_letter - defines the letter in the spot in the head of the class
spot_color - determines the fill color of the spot in the head
body_color - determines the fill color of the class body
header_color - determines the fill color of the class head
line_color - determines the color of the line that draws the class
line_style - determines the style of the line that draws the class
text_color - determines the color of the text in the class
body - the portion of the class that holds its attributes and methods
There are several options for class type. Simply replace class with any other class type. PlantUML will change the Spot letter and emphasis of the name based on the class type. Below is a list of class types. Annotation displays an @ sign in the spot while the others display the first letter of their type. The last three will appear with an italicized name.
annotation
class
entity
enum
interface
abstract
abstract class
Note: abstract and abstract class perform identically.
The alias is exactly that. It is a variable that represents a class. It is especially useful if the class has a long name. The variable for the alias follows the as keyword.
Notice how much easier it is to use the PersCare alias on line 14. Otherwise you must write the entire name as shown for Department Store.
The generic is an extra text field that attaches to the class head for further description. It is defined between a single set of greater than and less than signs. This field can be a string without quotations. It supports creole for emphasis. This is not the UML stereotype field.
The stereotype field is defined by text between a double set of greater than and less than signs. This adds a stereotype above the class name. The stereotype text will be displayed in the color of the text_color property. This field can be a string without quotations. It supports creole for emphasis.
The stereotype property contains three sub-properties. The first is the spot_letter. This allows you to chose the letter that appears inside the circle on the left side of the class head. The spot_letter is defined by placing a letter and its color inside a set of parentheses inside of the stereotype field. This letter will be the color defined by text_color. If you use spot_letter you must also define a spot_color.
The second stereotype sub-property is spot_color. This allows you to chose the color that appears inside the circle on the left side of the class head. The spot_color is defined by placing a standard color name or hex code inside a set of parentheses inside of the stereotype field. If you use spot_color you must also define a spot_letter.
The body_color property determines the fill color of the drawn class entity. The body_color is defined by a standard color name or hex code. Create a gradient by using two colors. If you use this property alone it must come after a hash (#) sign and touch the hash sign. If any other properties follow this place a semicolon (;) between them. No spaces are needed.
Note: If used with the header_color property, header_color will determine the color of the header. If used alone body_color will determine the color of the entire class.
The header_color property determines the fill color of the drawn class header. The header_color is defined by a standard color name or hex code. Create a gradient by using two colors. If you use this property alone it must come after a hash (#) sign and touch the hash sign. If any other properties follow this place a semicolon (;) between them. No spaces are needed.
Note: If used with body_color, the color of the header will be different than the body of the class. If used alone the body of the class will be the default color.
The line_color property determines the color of the line that draws the box of the class. The line_color is defined by a standard color name or hex code. Create a gradient by using two colors. If you use this property alone it must come after a hash (#) sign and touch the hash sign. If any other properties follow this place a semicolon (;) between them. No spaces are needed.
The line_style property determines the type of line that draws the box of the class. The line_style is defined by one of the three options below. If you use this property alone it must come after a hash (#) sign and touch the hash sign. If any other properties follow this place a semicolon (;) between them. No spaces are needed.
line.dashed
line.dotted
line.bold
The text_color property determines the color of the text in the class. The text_color is defined by a standard color name or hex code. If you use this property alone it must come after a hash (#) sign and touch the hash sign. If any other properties follow this place a semicolon (;) between them. No spaces are needed.
The body of the class displays the attributes and methods that belong to the class. The body automatically sorts attributes and methods into their predefined areas. Attributes and methods will be discussed in their own chapter.
There are two other entities that are declared similar to classes. Both have a shorthand version for declaration. The diamond does not display the class name.
diamond - class type command for creating a diamond entity
<> - shorthand for creating a diamond
circle - class type command for creating a circle entity
() - shorthand for creating a circle
Circle entities support the below list of class properties as seen in the above classes description. Diamond entities only support type and name.
type - determines the type of class, circle or diamond
name - name of the class, will not display for diamonds
body_color - determines the fill color of the class body
line_color - determines the color of the line that draws the class
line_style - determines the style of the line that draws the class
text_color - determines the color of the text in the class
The name is text that appears in the head of the class. The name can be a single word without quotation marks or it can be a string with quotation marks. Single word supports creole syntax for emphasis. The string method supports emphasis with creole and markup language. The string method also supports colors with markup language. You can define colors with a standard color name or hex code. See for a list of creole and markup options.
There will be a relationship in the following example. This is needed to show the importance of the alias. Relationships will not be explained here. See the section of this chapter for proper explanations.