SEEM4570 System Design and Implementation
Lecture 10 – UML
Introduction
• In the previous lecture, we talked about software development life cycle in a “conceptual level”• E.g. we need to write documents, diagrams, etc. But how to
write/draw them?
© 2017. Gabriel Fung. 2
UML (1)
• 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 propose the specification must guarantee they can use the specification to bring a product to a market 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.
© 2017. 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"
© 2017. Gabriel Fung. 4
UML (2)
• UML is used to specify, visualize, modify, construct and document the artifacts of an object-oriented software-intensive system. • UML offers a standard way to visualize a system's
blueprint.• It can be used with all processes, throughout the
software development life cycle, and across different implementation technologies.
© 2017. Gabriel Fung. 5
UML (3)
• 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)
© 2017. Gabriel Fung. 6
Structure Diagrams
• Emphasize the things that must be presented in the system.• Used extensively in documenting the software architecture
• 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
© 2017. Gabriel Fung. 7
Behavior Diagrams• Emphasize what must be happened in the system. • Used extensively to describe the functionality of the system• System managers and other non-programmers may find
them useful in explaining the system• Diagrams:• Activity diagram• UML 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)
© 2017. Gabriel Fung. 8
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
© 2017. Gabriel Fung. 9
Person# name:string– age:int
+setName(name:string)+getName()+setAge(age: int)+getAge()
#,+,– areknownas“visibility”(Seenextslide)
Class Diagram – Drawing
• Visibility – used to specify the visibility of the attributes and methods (not mandatory, but usually has)• + Public • – Private • # Protected
• Relationship – define the logical relationship among classes• Major relationships: Bi-directional, Uni-directional,
Aggregation, Reflexive, Generalization, Realization
© 2017. Gabriel Fung. 10
Bi-Directional Relationship
© 2017. Gabriel Fung. 11
Room– location:String– room:int
+setLocation(name:String)+getLocation():
Course– name:string– code: string
+setName(name:string)+getName():
0..* 0..1
Aclassroomcanbeassignedto0tomanycourses
Acoursecanbeassignedto0or1classroom
ItiscalledMultiplicity
Multiplicity Meaning
x..y xtoy(x≥0,y>0),e.g.0..1,0..2,2..6,…
x..* xor more
* Zero ormore
n nonly, e.g.1,4,10,…
assignedassigned
Uni-Directional Relationship
© 2017. Gabriel Fung. 12
Course– courseCode:String– description: String:
+setName(name:String)+getName():
Printer– printerID:String:
+setJob(courseCode:String)+getName():
0..*print
Inauni-directionalassociation,twoclassesarerelated,butonlyoneclassknowsthattherelationshipexists.Inthisexample,onlythePrinterclassknowstheexistenceoftheCourseclass.Thismodelingallowsprintersknowwhichcoursestheyareprinting,butthecoursesdonotknowtheyarebeingprinted.Thisloosensthecouplingoftheobjectsandthereforemakesthe
systemmoreadaptivetochanges.
Uni-Directional Relationship (cont'd)
© 2017. Gabriel Fung. 13
MyDB:+connect()+disconnect():
GameRecord::
GameStage1::
GameStage2::
Aggregation / Composition Relationship (1)
© 2017. Gabriel Fung. 14
Building– securityGuard:Person[]:
:
1..*has
Person::
Note:Anon-filldiamondindicatestherelationshipis“weak”,i.e.evenifBuildingis“destroyed”,Person(i.e.securityguards)willnotbe“destroyed”.
Buildinghasanon-trivialclass"Person"!That’swhyweneedtolinkitback!
Aggregation / Composition Relationship (2)
© 2017. Gabriel Fung. 15
Room::
Building– listOfRoom:Room[]:
:
1..*has
Buildinghasanothernon-trivialclass!That’swhyweneedtolinkitback!
Note:Thediamondis“filled”,whichmeansRoomdependsonBuilding,i.e.iftheBuildingis“destroyed”,thenallRoomswillalsobe“destroyed”.Thistypeof“strongaggregation”iscalledComposition
Aggregation / Composition Relationship (3)
• If necessary, we can have uni-directional relationship for aggregation/composition relationship
© 2017. Gabriel Fung. 16
B::
A::
B::
A::
Reflexive Relationship
© 2017. Gabriel Fung. 17
Room# subRoom:Room:
Building#name:String#listOfRoom:Room[]
:
1..*has
0..*contains
Aroomcontainssomerooms,e.g.RM101containsRM101AandRM101B
Akindofreflexiverelationship.Again,itcanbebi-directionaloruni-directional
Staff::
1supervisor
0..*supervises
AstaffhasonesupervisorAstaffsupervises0ormanystaff
Generalization Relationship
© 2017. Gabriel Fung. 18
Person# name:String:
+getName()
Student– studentID:String+getGPA()
Staff#salary:int+getOfficeLocation()
Professor– housingAllowance:int:
Admin Staff::
Generalizationrelationship
Realization Relationship (1)
© 2017. Gabriel Fung. 19
<<interface>>Person
+getName()
Student– studentID:String+getName()
Staff#salary:int+getName()
Professor– housingAllowance:int:
Admin Staff::
Generalizationrelationship
RealizationrelationshipItshouldcontainsnothing
Canonlybe+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.
© 2017. Gabriel Fung. 20
Realization Relationship (2)
Class Diagram Summary
© 2017. Gabriel Fung. 21
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
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.• Remember 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.
© 2017. Gabriel Fung. 22
Object Diagram Example
© 2017. Gabriel Fung. 23
Room# floor:int:
Building#name:String#listOfRoom:Room[]
:
1..*has
ERM301 :RoomFloor:3
ERB :Buildingname=ERBlistOfRoom =Vector<Room>
has
ERM401 :RoomFloor:4has
ERM506 :RoomFloor:5has
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.• Can help non-programmers to understand more about the
system as they may find class diagrams are too abstract.• May help programmers as well!
• Unfortunately, UML 2.4 specification provides no definition of object diagram!• It does not have a concrete definition of how it should be
drawn!
© 2017. Gabriel Fung. 24
Package Diagram
• Describes how a system is split up into logical groupings by showing the dependencies among these groupings.• Package is a namespace used to group together
elements that are semantically related and might change together. • Because package is a namespace, elements (e.g. programs)
inside the same package should have unique names. • A package can import/access/use other packages. • Package can also be merged with other packages.
© 2017. Gabriel Fung. 25
Package Diagram (cont’d)
• For example, in a Java program:
• A package is rendered as a tabbed folder:
© 2017. Gabriel Fung. 26
package webShoppingCart;
import basicWebComponent;import java.io.*;import ...:
public XXX extends GeneralShoppingCart{:
}
Thenameofthepackagethatwecreated
Weneedtoimportthesepackages
Wetrytogroupprogramsintopackagesforbetterresourcesmanagement.Sowealsoneedtotelltheprogrammershowtoimplementourideas!
WebShoppingCart
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.
© 2017. Gabriel Fung. 27
Package Diagram Example
© 2017. Gabriel Fung. 28
WebShopping
MobileShopping
MailShopping
Inventory
<<import>>
package
ShoppingCartPayment
<<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.
© 2017. Gabriel Fung. 29
Components
© 2017. Gabriel Fung. 30
AComponent
Services/interfacetobeprovidedtoothercomponents
Services/interfacerequiredfromothercomponents
AComponent
Services/interfacetobeprovidedtoothercomponents
AComponent
Services/interfacerequiredfromothercomponents
Component Diagram Example
© 2017. Gabriel Fung. 31
OrderProductServices Customer
Product
OrderProduct
CustomerDetail
ProductCode
Composite Structure Diagram
• Visualizes the internal structure of a class. • A kind of component diagram used in modeling a system
at 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.
© 2017. Gabriel Fung. 32
Composite Structure Diagram Example
© 2017. Gabriel Fung. 33
SearchEngine
Searchport
Searchbook
SearchCD
Requestport
RequestProduct
part
port
environment
AnotherService
connector
AportDoSth
OrderProductServices
Deployment Diagram
• Describes the hardware used in system implementations and the execution environments and artifacts (e.g. software) deployed on the hardware.
© 2017. Gabriel Fung. 34
Note:ThisisnotUMLstandardcomponents(forillustrationpurposeonly)
Deployment Diagram Example
© 2017. Gabriel Fung. 35
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
© 2017. Gabriel Fung. 36
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
© 2017. Gabriel Fung. 37
Use Case Diagram Example (cont'd)
© 2017. Gabriel Fung. 38
System
Actor
Visitor
Clerk
Bank
BuyAdmissionTicket
Payment
SeekHelp
Association/relationship
ManageMuseum
<<include>>
<<extend>>
MuseumManager
answer
Askquestion
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
© 2017. Gabriel Fung. 39
Use Case Diagram Example (cont'd)
© 2017. Gabriel Fung. 40
Visitor
Clerk
Bank
BuyAdmissionTicket
Payment
SeekHelp
Notethekeywordherealso
ManageMuseum
<<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).
© 2017. Gabriel Fung. 41
Activity Diagram Example
• Online shopping
© 2017. Gabriel Fung. 42
Searchitem
Viewitem
found
Notfound
Addtocart
like
dislike
Continueshopping
Checkout
Doneshopping
Activity Diagram Example (cont'd)
• Process Order
© 2017. Gabriel Fung. 43
ReceiveOrder
PaymentProblem
Sendinvoice
Shiporder
CloseOrder
PaymentOK
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.
© 2017. Gabriel Fung. 44
State Machine Diagram Example
• For example, in an ATM machine, there are three states, Idle, Active and Out of Service:
© 2017. Gabriel Fung. 45
StateMachineofATM
Idle
ActiveOutofServices
Putcard
Takecard
Damage
Fixed
Shutdown
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.
© 2017. Gabriel Fung. 46
Sequence Diagram Example
• A simple online bank about transfer money
© 2017. Gabriel Fung. 47
sd onlinebank
:bank:customer
TransferMoney
Response
Logout
RedirecttoHomepage
Sequence Diagram Example (cont'd)
• Note that a customer should be able to have multiple transfers!
© 2017. Gabriel Fung. 48
sd onlinebank
:bank:customer
TransferMoney
Response
Logout
RedirecttoHomepage
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!
© 2017. Gabriel Fung. 49
TransferMoney
Response
Inputreferencenumber
loop
opt
Sequence Diagram Example (cont'd)
• How about if the customer do not have enough money? We should not make the transfer!
© 2017. Gabriel Fung. 50
loop
opt Refer tothepreviousslide
TransferMoney
TransferOK
[enoughmoney]
[notenoughmoney]
Transferfail
alt
Sequence Diagram of Facebook
© 2017. Gabriel Fung. 51
Communication Diagram
• Represents a combination of information taken from Class, Sequence, and Use Case Diagrams, describing both the static structure and dynamic behavior of a system.• 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.
© 2017. Gabriel Fung. 52
Communication Diagram Example
© 2017. Gabriel Fung. 53
: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:inputcourseID1.2:clickenquiry1.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
© 2017. Gabriel Fung. 54
WebUserIdleWaitingViewing
BrowserIdleProcessingWaiting
ServerIdleProcessing 100ms
10ms20ms
Interaction Overview Diagram
• The interaction overview diagram is similar to combining activity diagrams, sequence diagrams and timing diagrams
© 2017. Gabriel Fung. 55
Interaction Overview Diagram Example
© 2017. Gabriel Fung. 56
References
• http://www.uml-diagrams.org/• http://www.uml.org/• https://creately.com/blog/diagrams/uml-diagram-
types-examples/• http://www.visual-paradigm.com/
© 2017. Gabriel Fung. 57