Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#53] Add section for reference frame #62

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tutorials/images/plantuml/OriginalSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions tutorials/images/plantuml/ParentReferenceFrameDiagram.puml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions tutorials/images/plantuml/ReferenceFrameDiagram.puml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tutorials/plantUml.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,17 @@ package "Rule Of Thumb";{

Explicitly define all symbols to avoid any potential layout mishaps.
</box>

### Using reference frames
mfjkri marked this conversation as resolved.
Show resolved Hide resolved

mfjkri marked this conversation as resolved.
Show resolved Hide resolved
mfjkri marked this conversation as resolved.
Show resolved Hide resolved
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:
<puml src="images/plantuml/OriginalSequenceDiagram.puml" width=500 />

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** <br><br> <pre>TextUi -> MSLogic : getAppearanceOfCellAt(x, y)<br>MSLogic -> TextUi : getConfig()<br>TextUi --> MSLogic : config<br>MSLogic --> TextUi : cellAppearance</pre> **with** <br><br> <pre>ref over MSLogic, TextUi : get minefield appearance</pre> | <puml src="images/plantuml/ParentReferenceFrameDiagram.puml" width=300 /> |
| <pre>group sd get minefield appearance<br>&emsp;&emsp;'Contents of reference frame <br>&emsp;&emsp;TextUi -> MSLogic : getAppearanceOfCellAt(x, y) <br>&emsp;&emsp;MSLogic -> TextUi : getConfig() <br>&emsp;&emsp;TextUi --> MSLogic : config <br>&emsp;&emsp;MSLogic --> TextUi : cellAppearance <br>&emsp;&emsp;deactivate MSLogic <br>end</pre> | <puml src="images/plantuml/ReferenceFrameDiagram.puml" width=300 /> |