diff --git a/tutorials/images/plantuml/OriginalSequenceDiagram.puml b/tutorials/images/plantuml/OriginalSequenceDiagram.puml new file mode 100644 index 00000000..7ac55f20 --- /dev/null +++ b/tutorials/images/plantuml/OriginalSequenceDiagram.puml @@ -0,0 +1,24 @@ +@startuml + +hide footbox +skinparam sequenceReferenceBackgroundColor #f7807c + +actor Player + +participant ":TextUi" as TextUi #EE82EE +participant ":MSLogic" as MSLogic #90EE90 + +Player -> TextUi : mark x y +TextUi -> MSLogic : markCellAt(x, y) +return + +'This sequence can be abstracted into a reference frame for simplicity +TextUi -> MSLogic : getAppearanceOfCellAt(x, y) +MSLogic -> TextUi : getConfig() +TextUi --> MSLogic : config +MSLogic --> TextUi : cellAppearance +'--- + +TextUi --> Player : Show updated minefield + +@enduml diff --git a/tutorials/images/plantuml/ParentReferenceFrameDiagram.puml b/tutorials/images/plantuml/ParentReferenceFrameDiagram.puml new file mode 100644 index 00000000..f8600402 --- /dev/null +++ b/tutorials/images/plantuml/ParentReferenceFrameDiagram.puml @@ -0,0 +1,21 @@ +@startuml + +hide footbox +skinparam sequenceReferenceBackgroundColor #f7807c + +actor Player + +participant ":TextUi" as TextUi #EE82EE +participant ":MSLogic" as MSLogic #90EE90 + +Player -> TextUi : mark x y +TextUi -> MSLogic : markCellAt(x, y) +return + +ref over TextUi, MSLogic + get minefield appearance +end ref + +TextUi --> Player : Show updated minefield + +@enduml diff --git a/tutorials/images/plantuml/ReferenceFrameDiagram.puml b/tutorials/images/plantuml/ReferenceFrameDiagram.puml new file mode 100644 index 00000000..9d61d33d --- /dev/null +++ b/tutorials/images/plantuml/ReferenceFrameDiagram.puml @@ -0,0 +1,16 @@ +@startuml + +hide footbox + +participant ":TextUi" as TextUi #EE82EE +participant ":MSLogic" as MSLogic #90EE90 + +group sd get minefield appearance + 'Contents of reference frame + TextUi -> MSLogic : getAppearanceOfCellAt(x, y) + MSLogic -> TextUi : getConfig() + TextUi --> MSLogic : config + MSLogic --> TextUi : cellAppearance +end + +@enduml diff --git a/tutorials/plantUml.md b/tutorials/plantUml.md index ee87602c..f6e51fe1 100644 --- a/tutorials/plantUml.md +++ b/tutorials/plantUml.md @@ -278,3 +278,17 @@ package "Rule Of Thumb";{ Explicitly define all symbols to avoid any potential layout mishaps. + +### Using reference frames + +Reference frames in PlantUML sequence diagrams allow you to **group and reuse sequences** of interactions, which helps improve readability and reduce repetition in complex scenarios. By encapsulating sequences into reference frames, you can also **reduce complexity**, making it easier to manage and understand the overall flow of interactions within your diagrams. + +Refer to the following example: + + +The sequence diagram illustrates two main actions: marking a cell and retrieving its appearance. We can simplify the diagram by moving the latter into a new reference frame. + +| Source | Result | +|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------| +| **Replacing**

TextUi -> MSLogic : getAppearanceOfCellAt(x, y)
MSLogic -> TextUi : getConfig()
TextUi --> MSLogic : config
MSLogic --> TextUi : cellAppearance
**with**

ref over MSLogic, TextUi : get minefield appearance
| | +|
group sd get minefield appearance
  'Contents of reference frame
  TextUi -> MSLogic : getAppearanceOfCellAt(x, y)
  MSLogic -> TextUi : getConfig()
  TextUi --> MSLogic : config
  MSLogic --> TextUi : cellAppearance
  deactivate MSLogic
end
| |