Architects and civil engineers create models of the things they are going to build
Model of a Bridge
Model of a Building
Model in Statistics / Machine Learning
In statistics (and machine learning) a model is a mathematical representation of a real-world process
(commonly attained by fitting a parametric function over a sample of data describing the process)
e.g.: $f(x) = \beta_0 + \beta_1 x $ where $f$ is the amount of minutes played, and $x$ is the age
else response has error
Actor –> Participant: shut down
destroy Participant
create participant “Another Participant” as Participant2
Actor –> Participant2: start another participant
end
@enduml
The diagram is vertical, each column corresponds to the life-line of a participant
The vertical axis corresponds to time, the lower, the later
Participants can be objects or entities of any sort (e.g. OOP objects, infrastructural components, etc.)
special icons may be used for special participants, such as actors or databases
participants are assumed to be alreadyup and running at the beginning of the sequence
yet they can be created and destroyed during the sequence
Horizontal arrows represent messages sent from one participant to another
the label of the arrow is the message itself
an informal description of the message can be used too, but formal is better
straight line is for requests, dashed line is for responses
White vertical bars on a participant’s life-line represent the control flows
i.e., the participant is active during that time
this is way to stress the duration of activities
participants get activated starting to process some received message, deactivated when done
Branching (if) or loops are represented via ad-hoc frames
Double horizontal lines may be used to denote a new interaction sequence
== Iterating Over Elements ==
loop
Client -> Iterator: next()
activate Iterator
Iterator -> Iterator: Check if more elements
alt More Elements Available
Iterator –> Client: return Current Item
else No More Elements
Iterator –> Client: raise StopIteration
deactivate Iterator
end
end
destroy Iterator
@enduml
Sequence Diagram Example in OOP (pt. 2)
Participants are named after classes, yet they refer to instances of those classes
Arrows are named after method calls when possible
The following pieces of code are completely equivalent in Python:
@startuml
hide footbox
actor User
participant "Web Browser" as Browser
participant "Web Server" as Server
database "Database" as DB
actor Admin
participant "Email Service" as EmailService
activate User
User -> Browser: Request Page
activate Browser
Browser -> Server: HTTP GET /homepage
activate Server
Server -> DB: Query User Data
activate DB
DB --> Server: User Data Response
deactivate DB
Server --> Browser: HTML Content
deactivate Server
Browser --> User: Render Page
deactivate Browser
== User Authentication Flow ==
User -> Browser: Enter Credentials
activate Browser
Browser -> Server: POST /login
activate Server
alt Valid Credentials
Server -> DB: Validate User
activate DB
DB --> Server: Success
deactivate DB
Server --> Browser: Set Auth Token
else Invalid Credentials
Server --> Browser: Authentication Error
end
deactivate Server
Browser --> User: Show Login Result
deactivate Browser
== Additional Features ==
User -> Browser: Perform an Action
activate Browser
Browser -> Server: Request Action
activate Server
par Parallel Processing
Server --> DB: Write Logs
activate DB
Server --> DB: Process Request
deactivate DB
end
Server --> Browser: Action Success
deactivate Server
Browser --> User: Display Confirmation
deactivate Browser
== Object Creation & Deletion ==
create EmailService
EmailService <- Admin: deploy
User -> Browser: Create New Account
activate Browser
Browser -> Server: Register User
activate Server
Server -> DB: Insert New User
activate DB
DB --> Server: Confirmation
deactivate DB
Server -> EmailService: Send Welcome Email
activate EmailService
Server --> Browser: Registration Successful
deactivate Server
Browser --> User: Show Confirmation
deactivate Browser
EmailService --> User: Welcome Email
deactivate EmailService
@enduml
State Diagram
Modelling the state of an object and the transitions among them
Focus on classes and how method calls affect their fields/properties
State Diagram Overview
State diagrams only make sense for mutable entities
0:00:00.000006 Color.GREEN on
0:00:01.005111 Color.GREEN off
0:00:02.010381 Color.GREEN on
0:00:03.011538 Color.GREEN off
0:00:04.013307 Color.GREEN on
0:00:05.033300 Color.GREEN off
0:00:06.038391 Color.GREEN on
0:00:07.043062 Color.GREEN off
0:00:08.048151 Color.GREEN on
0:00:09.051959 Color.GREEN off
0:00:10.057036 Color.GREEN on
0:00:10.057134 Color.YELLOW on
0:00:11.062204 Color.YELLOW off
0:00:12.065133 Color.YELLOW on
0:00:13.069653 Color.YELLOW off
0:00:14.074754 Color.YELLOW on
0:00:15.077038 Color.YELLOW off
0:00:15.077119 Color.RED off
0:00:16.080739 Color.RED on
0:00:17.085859 Color.RED off
0:00:18.090981 Color.RED on
0:00:19.096069 Color.RED off
0:00:20.099124 Color.RED on
0:00:21.104888 Color.RED off
0:00:22.106639 Color.RED on
0:00:23.111723 Color.RED off
0:00:24.116843 Color.RED on
0:00:25.118087 Color.RED off
0:00:26.123146 Color.RED on
0:00:27.126476 Color.RED off
0:00:28.128466 Color.RED on
0:00:29.133614 Color.RED off
0:00:30.138698 Color.RED on
Activity Diagram
Modelling the workflow of one or more processes
Like a flow chart, but more flexible and richer, and supporting parallelism
Overview on Activity Diagrams
Activity diagrams can represent socio-technicalworkflows
i.e. workflows involving people and machines
They can represent businessprocesses
e.g. order processing, customer service, product development
They can represent softwareprocesses
e.g. an algorithm, a use case, a system operation
Boxes represent activities, expressed in natural language
Several control structures are supported:
sequence (straight arrows): one activity follows the other
choiches (diamonds): a branch in the workflow
based on a condition
loops (back arrows): a cycle in the workflow
forks (black bars, opening): activities are started in parallel
joins (black bars, closing): activities are joined
joining an activity $\equiv$ waiting for its termination
Two sort of joins:
AND join: all activities must terminate
OR join: at least one (i.e. “any”) activity must terminate
Beginning and termination $\leftrightarrow$ explicit bullets
Example: Activity Diagram To Represent User Stories (pt. 1)
User Story: Creating & Shares a story on Instagram
As a: social media user,
I want to: create and share a temporary story on Instagram,
so that: I can share moments, updates, or engage with my followers in a fun and interactive way.
Acceptance Criteria
Accessing the Story Feature
Given that I am logged into Instagram,
When I tap on my profile picture or the “+” icon at the top of my feed,
Then I should be taken to the story creation interface.
Capturing or Uploading Content
Given that I am on the story creation screen,
When I take a photo/video using the camera or upload media from my gallery,
Then the selected media should appear as a preview for editing.
Editing the Story
Given that I have added media to my story,
When I tap on editing options (stickers, text, drawings, filters, or music),
Then I should be able to customize my story before posting.
Adding Interactive Elements
Given that I am editing my story,
When I choose elements like polls, Q&A, links, or mentions,
Then they should be added to my story for engagement.
Sharing the Story
Given that I have finalized my story,
When I tap on “Your Story” or “Close Friends,”
Then my story should be successfully shared and visible to my selected audience.
Viewing Story Engagement
Given that my story is live,
When I check my story views,
Then I should be able to see who has viewed and interacted with my story.
Deleting or Archiving the Story
Given that my story is posted,
When I tap on my story and select the delete or archive option,
Then I should be able to remove or save it before it expires.
Example: Activity Diagram To Represent User Stories (pt. 2)
Other relevant UML Diagrams by Example
Use Case Diagram
Modelling the actors interacting with a system and the use cases they can perform