Class diagrams: stereotypes and interfaces

Class diagrams: stereotypes and interfaces

puml.online

简介 / Introduction

Class diagrams are the core of object-oriented modeling. Beyond ordinary classes, stereotypes (such as <<interface>>, <<abstract>>, <<service>>) mark special semantic roles. The corresponding UML concepts are Interface and Abstract Class. This post shows how to write these in both PlantUML and Mermaid.

PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@startuml
skinparam classAttributeIconSize 0

interface "<<interface>>\nIProduct" as IProduct {
+ getPrice(): double
+ getName(): string
}

abstract class "<<abstract>>\nItem" as Item {
+ id: int
+ calculateDiscount(): double
}

class "Product" as Product {
+ price: double
+ name: string
+ getPrice(): double
+ getName(): string
}

class "Service" as Service {
+ fee: double
+ getPrice(): double
}

IProduct <|.. Product : implements
IProduct <|.. Service : implements
Item <|-- Product : extends
@enduml

Use the interface keyword, or annotate a class name with a stereotype. <<abstract>> is declared with abstract class. Implementation uses the dashed triangle <|..; inheritance uses the solid triangle <|--.

Mermaid 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
classDiagram
class IProduct {
<<interface>>
+ getPrice(): double
+ getName(): string
}

class Item {
<<abstract>>
- id: int
+ calculateDiscount(): double
}

class Product {
+ price: double
+ name: string
+ getPrice(): double
+ getName(): string
}

class Service {
+ fee: double
+ getPrice(): double
}

IProduct <|.. Product : implements
IProduct <|.. Service : implements
Item <|-- Product : extends

In Mermaid’s classDiagram, annotate a class with <<interface>> or <<abstract>> inside the class body. Implementation uses <|.. and inheritance uses <|--. Note Mermaid only supports + (public) and - (private) visibility modifiers.

对比 / Side-by-side

Feature PlantUML Mermaid
Interface declaration interface "<<interface>>\nName" or plain interface Name class Name { <<interface>> }
Abstract Class declaration abstract class "<<abstract>>\nName" class Name { <<abstract>> }
Implementation arrow `< ..`
Inheritance arrow `< –`
Attribute visibility + public, - private, # protected + public, - private (only two levels)
Skin parameters skinparam classAttributeIconSize 0 hides icons Not supported

小结 / Wrap-up

Stereotypes distinguish roles like interface, abstract class, and service in UML class diagrams. PlantUML renders stereotypes more richly (directly on the class name), while Mermaid uses inline {<<interface>>} annotations. Both engines share the same arrow syntax for implementation and inheritance. Choose based on your team’s tooling and the level of visual customization needed.

  • Title: Class diagrams: stereotypes and interfaces
  • Author: puml.online
  • Created at : 2026-09-02 08:00:00
  • Updated at : 2026-09-02 01:06:39
  • Link: https://puml.online/blog/class-diagram-stereotypes-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Class diagrams: stereotypes and interfaces