Unified Compliance NextGen
  • UCF NextGen
    • On-Boarding
    • PlantUML
      • Diagrams as Code
        • Why use diagrams as Code tools?
        • Use Cases
        • Introduction to PlantUML
        • Syntax
          • Basic PlantUML Syntax
          • Sequence Diagram
            • Lifelines
            • Messages
            • ExecutionSpecification
            • Autonumber
            • Notes
            • Interactions
            • Organization
          • Use Case Diagram
            • Use Case
            • Actor
            • Associations
            • Organization
            • Notes
          • Class Diagram
            • Classes and Other Entities
            • Attributes and Methods
            • Relationships
            • Organization
            • Notes
          • Object Diagram
            • Objects
            • Relations and Associations
            • Organization
            • Notes
          • Work Breakdown Structure Diagram
            • OrgMode Syntax
            • Arithmetic Notation
            • Styling
          • Activity Diagram
            • Actions and Other Objects
            • Arrows
            • Conditionals
            • Loops
            • Forks, Splits, and Merges
            • Notes
          • Text Formatting
          • Skin Parameters
    • Control Workspace
      • My Frameworks
        • Authority Document Details
        • Common Control Details
      • List Manager
      • Compare
      • Exports
    • UCF Catalog
    • Profile
    • Administration
      • Account Settings
        • General
        • Team
        • Organization
        • Industry
        • Groups
        • Initiatives
      • API Manager
      • Billing
    • API Gateway
Powered by GitBook
On this page
  • Declaration
  • Shorthand
  • Properties
  • Type
  • Name
  • Alias
  • Generic
  • Stereotype
  • Body Color
  • Header Color
  • Line Color
  • Line Style
  • Text Color
  • Body
  • With All Properties
  • Other Entities
  • Properties

Was this helpful?

Export as PDF
  1. UCF NextGen
  2. PlantUML
  3. Diagrams as Code
  4. Syntax
  5. Class Diagram

Classes and Other Entities

PreviousClass DiagramNextAttributes and Methods

Last updated 1 year ago

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.

Declaration

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.

Example: Declaring Classes

@startuml
'Example: Declaring Classes

'Create a basic class with a name.
class Name

@enduml

Shorthand

Properties

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

Type

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.

Example: Class Types

@startuml
'Example: Class Types

'Display all 7 basic class types with names.
annotation      annotation
class           class
entity          entity
enum            enum
interface       interface
abstract        abstract
abstract class  abstract_class

@enduml

Name

Example: Class Name

@startuml
'Example: Class Name

'Create a class with a single word name.
'Use creole for emphasis
class ~~Store~~

'Create a class with a name using the string method.
'Use markup for emphasis and color.
class "<color:#561D5E><b>Personal Care</b></color>"

@enduml

Alias

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.

Example: Class Alias

@startuml
'Example: Class Alias

'Create a multiword class with a name using the string method.
'Use markup for emphasis and color.
class "<color:#Purple><b>Department Store</b></color>"

'Create a class with a name using the string method.
'Use markup for emphasis and color.
'Give it an alias.
class "<color:#561D5E><b>Personal Care</b></color>" as PersCare

'Show a relationship between the two classes.
"<color:#Purple><b>Department Store</b></color>" <- PersCare

@enduml

Generic

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.

Example: Class Generics

@startuml
'Example: Class Generic

'Create a class.
'Add a generic.
class Store <generic descriptor>

'Create a class.
'Add a generic.
'Use creole for emphasis.
class "Personal Care" <**generic descriptor**>

@enduml

Stereotype

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.

Example: Class Stereotypes

@startuml
'Example: Class Generic

'Create a class.
'Add a stereotype.
class Store <<Focus>>

'Create a class.
'Add a stereotype.
'Add emphasis with creole.
class "Personal Care" <<**Auxiliary**>>

@enduml

Spot Letter

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.

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.

Example: Class Spot Letter and Spot Color

@startuml
'Example: Class Generic

'Create a class.
'Change the spot_letter and spot_color.
class Store << (S,darkgrey) >>

'Create a second class.
'Add a stereotype.
'Change the spot_letter and spot_color.
class "Personal Care" << (P,#FF7700) >>

@enduml

Body Color

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.

Example: Class Body Color

@startuml
'Example: Class Body Color

'Create a class.
'Add body_color.
class Store #back:purple;

'Create a class.
'Add a body_color with a gradient.
class "Personal Care" #back:561D5E/FFFFFF;

@enduml

Header Color

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.

Example: Class Body Color

@startuml
'Example: Class Header Color

'Create a class.
'Add header_color.
class Store #header:purple

'Create a class.
'Add a body_color with a gradient.
'Add a header color.
class "Personal Care" #back:561D5E/FFFFFF;header:purple

@enduml

Line 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.

Example: Class Line Color

@startuml
'Example: Class Line Color

'Create a class.
'Add line_color.
class Store #line:purple

'Create a class.
'Add line_color with a gradient.
class "Personal Care" #line:561D5E/FFFFFF

@enduml

Line Style

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

Example: Class Line Style

@startuml
'Example: Class Line Style

'Create a class.
'Leave a default line_style.
class Business 

'Create a class.
'Use a dashed line_style.
class Store #line.dashed

'Create a class.
'Use a dotted line_style.
class "Personal Care" #line.dotted

'Create a class.
'Use a bold line_style.
class Cooking #line.bold

@enduml

Text Color

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.

Example: Class Text Color

@startuml
'Example: Class Text Color

'Create a class.
'Add text_color.
class Store #text:purple

'Create a class.
'Add text_color.
class "Personal Care" #text:561D5E

@enduml

Body

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.

Example: Class Body

@startuml
'Example: Class Text Color

'Create a class with a body.
'Add one attribute and one method.
class Store {
    attribute
    method()
}

@enduml

With All Properties

Example: Class With All Properties

@startuml
'Example: Class With All Properties

class "class_name" as alias <generic> << (N,orchid) stereotype>> #back:blue/red;header:purple;line:white;line.dotted;text:white {
    attribute
    method()
}

@enduml

Other Entities

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

Properties

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

Example: Circle and Diamond Entities

@startuml
'Example: Circle and Diamond Entities

'Create a circle.
circle circle_name_1

'Create a circle with shorthand.
'Change all available properties.
() circle_name_2 #back:blue/red;line:white;line.dotted;text:blue

'Create a diamond.
diamond diamond_name_1 

'Create a diamond with shorthand.
<> diamond_name_2

@enduml

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.

Text Formatting
relationships
Declaring Classes
Class Types
Class Names
Class Alias
Class Generics
Class Stereotypes
Class Spot Letter
Class Body Color
Class Header Color
Class Line Color
Class Line Style
Class Text Color
Class Body
Class With All Properties
Circle and Diamond Entities