SEEM3430Information Systems Analysis and Design
UML
Introduction
• In the previous lecture, you should probably learned SDLC (e.g. waterfall, agile, etc.) and should understand the importance of documentation, diagrams, etc.• Now the problem is – how to write the
documentation and draw the diagrams?
© 2021. Gabriel Fung. 2
UML
• Unified Modeling Language (UML) is a standardized general-purpose modeling language in the field of object-oriented software engineering. • The standard is managed, and was created, by OMG.
• OMG – Object Management Group – a consortium. • UML provides specifications but not implementation.
• Before a specification can be accepted as a standard by OMG, the team which proposes the specification must use the specification to bring a product within 1 year. • This prevents un-implementable standard.
• UML was in the list of OMG adopted technologies in 1997, and also the industry standard for modeling software-intensive systems.
© 2021. Gabriel Fung. 3
Side Track: About Consortium
• A consortium is an association of two or more individuals, companies, organizations or governments (or any combination of these entities) with the objective of participating in a common activity or pooling their resources for achieving a common goal.• Consortium is a Latin word, meaning "partnership",
"association" or "society"• Con = "together"• Sors = "fate"• Consors = "Partner"
© 2021. Gabriel Fung. 4
UML (cont’d)
• Current version is UML 2.4• It has 14 types of diagrams divided into two categories• Each category represents a different view of a model
(discuss in the next two slides)
© 2021. Gabriel Fung. 5
Structure Diagrams
• Emphasize the things that must be presented in the system.• Programmers will find them very useful in writing programs
• Diagrams:• Class diagram• Object diagram• Package diagram• Component diagram• Composite structure diagram• Profile diagram• Deployment diagram
© 2021. Gabriel Fung. 6
Behavior Diagrams
• Emphasize what must be happened in the system. • Non-programmers may find them useful in explaining the
system• Diagrams:• Activity diagram• State machine diagram• Use case diagram• Communication diagram (a kind of interaction diagram)• Interaction overview diagram (a kind of interaction
diagram)• Sequence diagram (a kind of interaction diagram)• Timing diagram (a kind of interaction diagram)
© 2021. Gabriel Fung. 7
UML in This Course
© 2021. Gabriel Fung. 8
• There are thousands of books talking about UML (each has a few hundred pages).• We will focus on the “big-picture”: discuss the core
UML components and their ideas.
Class Diagram – Overview
• Describes the structure of a system by showing the system's classes, attributes, and relationships among classes• In a class diagram, there are many classes. Each class
is represented by a box with three parts:• Top: The name of the class• Middle: The properties/attributes of
the class• Bottom: The methods of the class
© 2021. Gabriel Fung. 9
Person
# name: string– age: int
+ setName(name: string)+ getName()+ setAge(age: int)+ getAge()
#, +, – are known as “visibility”. Not Mandatory.
+ Public – Private # Protected
Class Diagram Summary
© 2021. Gabriel Fung. 10
Class A
Class B
Class A
Class B
Class A
Class B
Class A
Class B
Class A
Class B
Class A
Class B
Class A
Bi-Directional Uni-Directional
Reflexive
Aggregation Composition Realization Generalization
Bi-Directional Relationship
© 2021. Gabriel Fung. 11
Room
– location: String– room: int
+ setLocation(name:String)+ getLocation():
Course
– name: string– code: string
+ setName(name:string)+ getName():
0..* 0..1
A classroom can be assigned to 0 to many courses
A course can be assigned to 0 or 1 classroom
It is called Multiplicity
Multiplicity Meaning
x..y x to y (x ≥ 0, y > 0), e.g. 0..1, 0..2, 2..6, …
x..* x or more
* Zero or more
n n only, e.g. 1, 4, 10, …
assignedassigned
Uni-Directional Relationship
© 2021. Gabriel Fung. 12
Course
– courseCode: String– description: String:
+ setName(name: String)+ getName():
Printer
– printerID: String:
+ setJob(courseCode: String)+ getName():
0..*print
In a uni-directional association, two classes are related, but only one class knows that the relationship exists. In this example, only the Printer class knows the existence of the Course class. This allows printers know which courses they are printing , but the courses do not know they are being printed. This loosens the coupling of the objects and therefore makes the
system more adaptive to changes.
Uni-Directional Relationship (cont'd)
© 2021. Gabriel Fung. 13
MyDB
:
+ connect()+ disconnect():
GameRecord
:
:
GameStage1
:
:
GameStage2
:
:
Aggregation Relationship
© 2021. Gabriel Fung. 14
Building
– securityGuard: Person[]:
:
1..*has
Person
:
:
Note: A non-fill diamond indicates the relationship is “weak”, i.e. even if Building is “destroyed”, Person (i.e. security guards) will not be “destroyed”.
Building has a non-trivial class "Person"! That’s why we need to link it back!
Composition Relationship
© 2021. Gabriel Fung. 15
Room
:
:
Building
– listOfRoom: Room[]:
:
1..*has
Building has another non-trivial class! That’s why we need to link it back!
Note: The diamond is “filled”, which means Room depends on Building, i.e. if the Building is “destroyed”, then all Rooms will also be “destroyed”. This type of “strong aggregation” is called Composition
Aggregation / Composition Relationship
• If necessary, we can have uni-directional relationship for aggregation/composition relationship
© 2021. Gabriel Fung. 16
B
:
:
A
:
:
B
:
:
A
:
:
Reflexive Relationship
© 2021. Gabriel Fung. 17
Room
# subRoom: Room
:
Building
# name: String# listOfRoom: Room[]
:
1..*has
0..*contains
A room contains some rooms, e.g. RM101 contains RM101A and RM101B
A kind of reflexive relationship.Again, it can be bi-directional or uni-directional
Staff
:
:
1supervisor
0..*supervises
A staff has one supervisorA staff supervises 0 or many staff
Generalization Relationship
© 2021. Gabriel Fung. 18
Person
# name: String:
+ getName()
Student
– studentID: String
+ getGPA()
Staff
# salary: int
+ getOfficeLocation()
Professor
– housingAllowance: int
:
Admin Staff
:
:
Generalization relationship
Realization Relationship
© 2021. Gabriel Fung. 19
<<interface>>Person
+ getName()
Student
– studentID: String
+ getName()
Staff
# salary: int
+ getName()
Professor
– housingAllowance: int
:
Admin Staff
:
:
Generalization relationship
Realization relationshipIt should contains nothing
Can only be + or #
• What is realization?• Realization is one of the major properties of Object
Oriented (OO) modeling, it implements an interface.• Don’t confuse with GUI (graphical user interface). This interface did
nothing with GUI.• In OO Programming, if a class is defined as an interface, it
does not have any implementation detail.• Hence, we need to write the details that are defined in the interface
in the implementing classes.• In the diagram in the previous slide, we need to write the
“getName” method in the Student Class and Staff Class.• It is the responsibility of the program designer to drop down every
single implementation issue carefully and clearly in the diagram.
© 2021. Gabriel Fung. 20
Generalization vs. Realization
Object Diagram
• An object diagram in the Unified Modeling Language (UML), is a diagram that shows a complete or partial view of the structure of a modeled system at a specific time.• Do you know the differences between Class and Object?
• Object diagrams are more concrete than class diagrams, and are often used to provide examples.• An Object diagram focuses on some particular set of object
instances and attributes, and the links between the instances.
© 2021. Gabriel Fung. 21
Object Diagram Example
© 2021. Gabriel Fung. 22
Room
# floor: int
:
Building
# name: String# listOfRoom: Room[]
:
1..*has
ERB301 : Room
Floor: 3
ERB : Building
name = ERBlistOfRoom = Array<Room>
has
ERB401 : Room
Floor: 4has
ERB506 : Room
Floor: 5has
The corresponding Objective Diagram:
Class Diagram:
Object Diagram – More Information
• Object diagrams help clarify classes and inheritance• They are useful to demonstrate what would happen in
the system at a specific time.• Object diagram let us understand more about the system
since class diagrams can be too abstract.
• Unfortunately, UML 2.4 specification does not have a concrete definition of how it should be drawn!• So we probably stop here.
© 2021. Gabriel Fung. 23
Package Diagram
• Describes how a system is split up into logical groupings by showing the dependencies among these groupings.• Used to group elements that are related and might
change together. • A package can import/access/use other packages. • Package can also be merged with other packages.
© 2021. Gabriel Fung. 24
Package Diagram (cont’d)
• For example, in a Java program:
• A package is rendered as a tabbed folder:
© 2021. Gabriel Fung. 25
package webShoppingCart;
import basicWebComponent;import java.io.*;import ...:
public XXX extends GeneralShoppingCart{:
}
The name of the package that we created
We need to import these packages
We try to group programs into packages for better resources management. So we also need to tell the programmers how to implement our ideas!
Web Shopping Cart
Notations
• Import• A relationship that shows the model elements in a package
which are to be imported from another package and the visibility is public
• Access• A relationship that shows the model elements in a package
which are to be imported from another package and the visibility is private, i.e. other packages that merge/import it cannot access the packages it has accessed• Note that it may be impossible to implement.
• Merge• A relationship between two packages showing that their
contents are to be combined.
© 2021. Gabriel Fung. 26
Package Diagram Example
© 2021. Gabriel Fung. 27
Web Shopping
MobileShopping
MailShopping
Inventory
<<import>>
package
Shopping CartPayment
<< import >><<merge>><<merge>><<import>>
<< access>>
Utility
<<import>>
Component Diagram
• Describes how a software system is split up into components and shows the dependencies among these components.• Developers find the component diagram useful because it
provides them with a high-level, architectural view of the system• Although may not be able to implement the system (too
abstract), it helps developers formalizing a roadmap for the implementation, and make decisions about task assignments.
• System administrators find component diagrams useful because they get an early view of the logical software components that will be running on their systems.
© 2021. Gabriel Fung. 28
Components
© 2021. Gabriel Fung. 29
A Component
Services to be providedto other components
Services requiredfrom other components
A Component
Services to be providedto other components
A Component
Services requiredfrom other components
Component Diagram Example
© 2021. Gabriel Fung. 30
OrderProduct Services Customer
Product
OrderProduct
Customer Detail
Product Code
Composite Structure Diagram
• Visualizes the internal structure of a class. • Similar to component diagram but at a micro point-of-view.
• The key entities are:• Part
• A role played at runtime by an object or by a collection of objects• Port
• An interaction point that can be used to connect other parts or the environment.
• Connector• It binds entities together, allowing them to interact at runtime.
• Collaborator• Represents by dotted oval. An abstract idea.
© 2021. Gabriel Fung. 31
Composite Structure Diagram Example
© 2021. Gabriel Fung. 32
Search Engine
Search port
Search book
Search CD
Request port
Request Product
part
port
environment
Another Service
connector
A portDo Sth
Order Product Services
Deployment Diagram
• Describes the hardware used in system implementations and the execution environments and artifacts (e.g. software) deployed on the hardware.
© 2021. Gabriel Fung. 33
Note: This is not UML standard components (for illustration purpose only)
Use Case Diagram
• Describe a set of actions (use cases) that some systems should or can perform in collaboration with one or more external users (actors). • Each use case should provide some observable and
valuable result to the user of the system.• Used to specify what the system should do but not
how the system should do.• Major elements of the use case diagram are:• Actor• Association / Relationship• Subject / System• Use case
© 2021. Gabriel Fung. 34
Use Case Diagram Example
• Consider:• In a museum, visitors can purchase admission ticket
through a clerk.• Purchasing admission ticket requires a payment system,
which will be connected to a bank.• Note that purchasing admission ticket is a kind of help. • In the museum, there is a manager who will mange the
daily activities of the museum
© 2021. Gabriel Fung. 35
Use Case Diagram Example (cont'd)
© 2021. Gabriel Fung. 36
System
Actor
Visitor
Clerk
Bank
Buy Admission
Ticket
Payment
Seek Help
Association / relationship
Manage Museum
<<include>>
<<extend>>
MuseumManager
answer
Ask question
Use Case Diagram Example (cont'd)
• Another example:• In a museum, visitors can purchase admission ticket
through a clerk.• Purchasing admission ticket requires a payment system,
which will be connected to a bank.• Note that the visitors can seek help when purchasing
admission ticket. • In the museum, there is a manager who will mange the
daily activities of the museum
© 2021. Gabriel Fung. 37
Use Case Diagram Example (cont'd)
© 2021. Gabriel Fung. 38
Visitor
Clerk
Bank
Buy Admission
Ticket
Payment
Seek Help
Note the keyword here also
Manage Museum
<<include>>
<<include>>
MuseumManager
$$$
answer
Activity Diagram
• Graphical representations of workflows of stepwise activities and actions with support for choice, iteration and concurrency. • Constructed from a limited number of shapes,
connected with arrows. Common shapes:• Rounded rectangles represent activities;• Diamonds represent decisions;• Bars represent the start (split) or end ( join) of concurrent
activities;• A black circle represents the start (initial state) of the
workflow;• An encircled black circle represents the end (final state).
© 2021. Gabriel Fung. 39
Activity Diagram Example
• Online shopping
© 2021. Gabriel Fung. 40
Search item
View item
found
Not found
Add to cart
like
dislike
Continue shopping
Check out
Done shopping
Activity Diagram Example (cont'd)
• Process Order
© 2021. Gabriel Fung. 41
Receive Order
Payment Problem
Send invoice
Ship order
Close Order
Payment OK
State Machine Diagram
• Describes the states and state transitions of the system• Many software systems are event-driven• They continuously wait for the occurrence of some external
or internal event such as a mouse click, a button press...
• The response to an event generally depends on the type of the event and the state of the system• E.g. if the user want to add an item to the shopping cart,
but the shopping cart module is not available (i.e., the stateof shopping cart module is down), then the user cannot perform the “add item” action.
© 2021. Gabriel Fung. 42
State Machine Diagram Example
• For example, in an ATM machine, there are three states, Idle, Active and Out of Service:
© 2021. Gabriel Fung. 43
State Machine of ATM
Idle
ActiveOut of Services
Put card
Take card
Damage
Fixed
Shut down
Sequence Diagram
• Sequence diagram is the most common kind of interaction diagram, which focuses on the message interchange between a number of lifelines. • A sequence diagram shows, as parallel vertical lines
(lifelines), different processes or objects that live simultaneously, and, as horizontal arrows, the messages exchanged between them, in the order in which they occur. This allows the specification of simple runtime scenarios in a graphical manner.
© 2021. Gabriel Fung. 44
Sequence Diagram Example
• A simple online bank about transfer money
© 2021. Gabriel Fung. 45
sd online bank
:bank:customer
Transfer Money
Response
Logout
Redirect to Homepage
Sequence Diagram Example (cont'd)
• Note that a customer should be able to have multiple transfers!
© 2021. Gabriel Fung. 46
sd online bank
:bank:customer
Transfer Money
Response
Logout
Redirect to Homepage
loop
Sequence Diagram Example (cont'd)
• We also want to add an option to our customers, such that they can input note before making a transfer!
© 2021. Gabriel Fung. 47
Transfer Money
Response
Input reference number
loop
opt
Sequence Diagram Example (cont'd)
• How about if the customer do not have enough money? We should not make the transfer!
© 2021. Gabriel Fung. 48
loop
opt Refer to the previous slide
Transfer Money
Transfer OK
[enough money]
[not enough money]
Transfer fail
alt
Sequence Diagram of Facebook
© 2021. Gabriel Fung. 49
Communication Diagram
• Communication diagrams show a lot of the same information as sequence diagrams, but are clearer to show the interaction among elements, whereas sequence diagrams are clearer to show the order in which the interactions take place.• Uses free-form arrangement of objects and links. To
maintain the ordering of messages, messages are labeled with a chronological number and placed near the link the message is sent. • Reading a communication diagram involves starting at
message 1.0, and following the messages from object to object.
© 2021. Gabriel Fung. 50
Communication Diagram Example
© 2021. Gabriel Fung. 51
:courseDetail :course
2: getCourseName(courseID): string3: getLocation(): json4: getStudentList(): array
:student
4.1: getStudentName(studentID): string4.2: getStudentMajor(studentID): string
:location
3.1: getBuildingName(locationID): string3.2: getLocationName(locationID): string
:staff
1.1: input courseID1.2: click enquiry1.3: enquiry(courseID): object
Timing Diagram
• Used to show interactions when the primary purpose of the diagram is to reason about time. • Timing diagrams focus on conditions changing within
and among lifelines along a linear time axis
© 2021. Gabriel Fung. 52
Web UserIdleWaitingViewing
BrowserIdleProcessingWaiting
ServerIdleProcessing 100ms
10ms20ms
Interaction Overview Diagram
• It looks like combining activity diagrams, sequence diagrams and timing diagrams to get a big picture of the system, but each diagram contains very brief ( just enough) information.
© 2021. Gabriel Fung. 53
References
• http://www.uml-diagrams.org/• http://www.uml.org/• https://creately.com/blog/diagrams/uml-diagram-
types-examples/• http://www.visual-paradigm.com/
© 2021. Gabriel Fung. 54