Domain model diagrams using PlantUML
Recreating the diagrams described in Ch. 1 ‘Document your domain’ and Ch. 2 ‘Enhance your domain model’ of Creating software with modern diagramming by Ashley Peacock, using PlantUML
See Software design diagrams using PlantUML for the other posts in the series.
These diagrams are generated using the -Smonochrome=true and -Sshadowing=false flags.
Entities in a domain model and how they are related (class diagram)
Association: loose relation, exist independently, neither owns the other. example: title – genre
Composition: the “child” entity cannot exist independently of the “parent”. examples: title – season, season – episode, title – review
Aggregate: can exist independently, but one is the “parent” (owner of the relationship). example: title – actor
@startuml
Title -- Genre
Title *-- Season
Title *-- Review
Season *-- Episode
Title o-- Actor
@enduml
Generalisation: represents inheritance (subtypes). example: title ∈ {tv show, film, short}
@startuml
"TV show" --|> Title
Short --|> Title
Film --|> Title
@enduml
Descriptions of the relationships can be added as labels on the vertices:
@startuml
Title -- Genre: "is associated with"
Title *-- Season: has
Title *-- Review: has
Season *-- Episode: contains
Season *-- Review: has
Episode *-- Review: has
Title o-- Actor: features
"TV show" --|> Title: implements
Short --|> Title: implements
Film --|> Title: implements
Viewer --> Title: watches
@enduml
Multiplicity of a relation (one-to-one, one-to-many, many-to-many, etc.)
is described by specifying the cardinality on each end of the vertex.
For example, each title (1) has zero or more seasons (0..*).
@startuml
Title "1..*" -- "1..*" Genre: "is associated with"
Title "1" *-- "0..*" Season: has
Title "1" *-- "0..*" Review: has
Season "1" *-- "1..*" Episode: contains
Season "1" *-- "0..*" Review: has
Episode "1" *-- "0..*" Review: has
Title "0..*" o-- "1..*" Actor: features
"TV show" --|> Title: implements
Short --|> Title: implements
Film --|> Title: implements
Viewer "0..*" --> "0..*" Title: watches
@enduml
Improving the visual style:
- add a title
- hack to increase spacing: add newlines in name or fields/methods on central entity
title Streamy Domain Model
' added to improve readability
class "\n\nTitle\n\n" as Title
/' alternative
class Title {
\n
--
\n
}
'/
Note: Unlike in Mermaid, it isn’t possible to add a hyperlink to an entity in a class diagram, though it is possible on a Gantt diagram.