Thursday 1 June 2023

PlantUML: Draw one to many relationship in class diagram

To model one to many relationship, you can use double-quotes "" on each side of the relation.

 

Example

Human "1" -- "many" BodyParts
Human "1" -- "1..*" BodyParts

Above one specifies that one human has many body parts.

 

oneToMany.txt

@startuml

title "Class Composition"

class Human

class BodyParts

Class Brain
class Lungs
class Liver
class Heart
class Stomach
class Kidney
class Bladder

class Frontal
class Parietal
class Temporal
class Occipital

Human "1" -- "many" BodyParts

BodyParts <|-- Brain : contains
BodyParts <|-- Lungs : contains
BodyParts <|-- Liver : contains
BodyParts <|-- Heart : contains
BodyParts <|-- Stomach : contains
BodyParts <|-- Kidney : contains
BodyParts <|-- Bladder : contains

Brain *-- Frontal : contains
Brain *-- Parietal : contains
Brain *-- Temporal : contains
Brain *-- Occipital : contains

@enduml

Above snippet generate below diagram.





 

Previous                                                    Next                                                    Home

No comments:

Post a Comment