Class diagrams: stereotypes and interfaces
简介 / 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 | @startuml |
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 | classDiagram |
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.