Académique Documents
Professionnel Documents
Culture Documents
UML Diagrams
Ioan Salomie
Spring 2012
Programming Techniques
Associations
Binary
OO Programming Techniques
Association
Name, Role, Multiplicity
* Student * advisee
OO Programming Techniques
Associations
Bi-directional
ResearchProj * public class ReseachProj { private Professor theProfessor; public ResearchProj() { .. .}; }
1 Professor
OO Programming Techniques
Associations
Uni-directional
ResearchProj * public class ResearchProj { public ResearchProj() { }; }
1 Professor
Associations
Reflexive associations
class Course { public: public Course() { } // the unbounded multiple association // is stored in a Vector private ArrayList prerequisites; }
Association
Association classes
Association as Example
class
representation
* Person
1 Company
Contract
Associations
Qualifiers to reduce multiplicity
a) Association
b) Association traversal
c) Qualifier
Aggregation
Special
Representation
UML
bicycle 1 frame
2 wheel
10
Aggregation Examples
Strong and weak aggregation
1 Bank * Branch 1 1..* Customer
1 Director 1 Staff
1 Clerck 1..*
Car
1 Body
4 Wheel
1 Engine
11
UML Diagrams
Model
Class and object diagrams - illustrate logical structure of the system Sequence, Collaboration, State diagrams illustrate system behaviour Activity diagrams - illustrate the flow of events in a use case Package diagrams - shows packages of classes and their dependencies Component diagrams - illustrate physical structure of software Deployment diagrams - shows the mapping of software to hardware configurations
Prof. Ioan Salomie Programming Techniques
12
the classes and objects in the system and the relationships among them
static relationships
associations aggregation generalization (inheritance)
For
13
Class diagrams
Three perspectives
Conceptual
draw a diagram representing the concepts in the problem domain not related to implementation focused on
functionality relationships among concepts
Specification
software perspective behavioural approach (interfaces) not implementation
Implementation
proper classes with attributes and operations
Notes
the lines between the three approaches is not very clear not big differences between conceptual and specification there are notable differences between specification diagrams and implementation ones
14
Class diagrams
Conceptual level
Example 1
15
Class diagrams
Conceptual level
Example 2
Catalogue
* Component
* CatalogueEntry
Assembly
Part
16
Class diagrams
Implementation level Example - Delivery department
Customer { abstract } #customerID : String #address: String getHistory(): String Order - dateReceived : Date - orderNumber : String - value : int - isPrepaid : bool dispatch() close() CorporateCustomer - name : String - creditLimit : int PersonalCustomer - creditCardNo : String getHistory(): String getHistory(): String - quantity : int - unitPrice : int 1 * OrderLine
1 Product
17
Class diagrams
Implementation level Example - TreeMap
Adapted from: R.C.Martin UML for Java Programmers, Prentice Hall, 2002
18
Object diagrams
Example TreeMap Object Diagram
Adapted from: R.C.Martin UML for Java Programmers, Prentice Hall, 2002
19
introduced in SE by Ivar Jacobson (1992) central concept in Rational Unified Process (RUP) process and UML a use case represents a set of scenarios related to how the system is used
Use
UML
introduces use case diagrams to graphically capture system actors, usecases and their relationships
20
actor
Actor - a role a human person, machine or software play during system operation The actor interacts (communicates) with the system Actor roles
Use-case
actor identification
Main actors and how they interact with the system to achieve system functionality Further iterations - identify and classify other actors
usually they support the primary actors
Use-cases
and actors
A use case describes the way actors interact with the system Use cases are built after the identification of the primary actors
21
System
Use-case
actor
ATM
withdraw money
22
System Actor
DVM
Use - case
Buy drink
Update stock
Customer
Collect
Agent
Maintenance Engineer
23
Use-case description
Use
Use-case
document
document about the sequence of actor system interaction (can be written in natural language)
24
Use-case description
Use
case example [Fowler] Actor: customer System: on line e-Commerce system Description:
The customer browses the catalog and adds desired items to the shopping basket. When the customer wishes to pay the customer describes the shipping and credit card information and confirms the sale. The system checks the authorization on the credit card and confirms the sale both immediately and with a follow-up e-mail.
This
scenario is one way of how things can happen The credit card authorization might fail that is another scenario
25
Interaction diagrams
Describe
how groups of objects collaborate Typically captures the behaviour of a single use-case
shows the objects involved and the messages passed among the objects
Shows
26
Sequence diagrams
Concepts
Message
arrows pointing from a lifeline of a sending object to the lifeline of a receiving object messages have names and may have arguments each message moves the flow of control from one object to another
Scenario
a use case may contain more scenarios one of the scenario is the best case scenario other scenarios can describe different events and conditions in the use case example:
use case buy drink from a vending machine best-case scenario no change to return scenario (will return the amount and cancel transaction)
27
Sequence diagrams
Concepts
Activation
narrow rectangle below the object along with the lifeline the period of time during which the object is processing the message when an object finishes processing a message the control returns to the sender of the message. This marks the end of the activation corresponding to that message. it is marked by a dashed arrow going from the bottom of the activation rectangle back to the lifeline of the object that send the message activations and return messages are optional in a sequence diagram
In
the course of message processing one object may send messages to other objects
Prof. Ioan Salomie Programming Techniques
28
29
Client Insert(amount)
: Panel
: Controller
: Delivery
30
Sequence diagrams
Buy drink use-case Generic Sequence diagrams
Takes
into account the flow of control Allow more scenarios in the diagram The next diagram shows the sequence diagram for incorrect-amount-of-money scenario Each condition causes a fork of control in the message separating the message into paths Conditions are represented in square brackets
[amount = price]
Another scenario
drink
31
Sequence diagrams
Buy drink use-case Generic Sequence diagrams
Client Insert(amount) Transfer(amount) Select(item) 1 [amount > price Check for change 2 [can do change] return(change) 3 [can do change] deliver the item 4 [can not do change] return(amount) cancel transaction deliver(item) 2 4 deliver(item) [amount = price] 1 3
: Panel
: Controller
: Delivery
32
Sequence diagrams
Object Creation and Destruction
: object1 :object2
: object1
:object2
: anObject
<< destroy>>
33
Sequence diagrams
Iterated messages
1 Assembly * Component class
: Assembly
: Component *
objects
: aClient
: Assembly
: Component *
cost() * cost()
34
Activity diagrams
Concepts
activity a state of performing some tasks (a method of a class, a real world activity (e.g. digging, eating, etc.))
activity diagram describes sequences of activities support for conditional and parallel behavior
transition branch
a decision point at which there are two or more possible path of flow of control single incoming transition several guarded outgoing transitions the branch is mutual exclusive [else] all others are false guard boolean expression
Prof. Ioan Salomie Programming Techniques
35
Activity diagrams
Concepts (cont.)
merge
multiple entry transitions single output marks the end of conditional behavior
fork
one incoming transition several outgoing transitions when the incoming trans. is triggered, the outgoing transitions are taken in parallel can specify concurrent programming
join
multiple entry transitions one outgoing transition synchronization role
The
representation symbols of the main concepts are shown in the activity diagram example on the next slide
Prof. Ioan Salomie Programming Techniques
36
Activity diagrams
Example Order processing
Adapted from: M.FowlerUML Distilled, Addison Wesley 2000
Start Fork Guard condition Prepare goods [rush ord] Branch Receive Order
Activity
Send Invoice
Receive Payment
Overnignt Delivery
Join
37
Activity diagrams
Composite activities
[adapted from m.fowler]
Receive Order
Prepare goods Delivery [rush ord] Overnignt Delivery [else] Regular Delivery
Send Invoice
Receive Payment
Close Order
38
Activity diagrams
Swim lanes
The
activities and actions of an activity diagram can be grouped into swim lanes The activities in each lane can be associated to a department (part) of an organization The lane borders are strictly conceptual delimited
39
Activity diagrams
Swim lanes
Warehouse Customer Service Accounting Dept.
Receive Order
Prepare goods
Delivery
Close Order
40
Package diagrams
diagrams help decomposition of large systems into subsystems In UML a package is a collection of modelling elements that are grouped together because they are logically related When defining packages, the principles of cohesion and coupling should be applied UML Package symbol (see next slide) may contain:
Package
41
Package diagrams
Ideally
only changing to a class interface should affect any other class m.fowler: the art of large-scale design involves minimizing dependencies
During analysis in the early stages of design, package diagrams can be used to show logical grouping of class diagrams into sub-systems packages During implementation, package diagrams can be used to show the grouping of physical components into sub-systems
Prof. Ioan Salomie Programming Techniques
42
Package diagrams
Example
Adapted from: M.FowlerUML Distilled, Addison Wesley 2000
Graphics Library
Domain
Orders
Customers
Oracle Interface
MSQL Interface
Prof. Ioan Salomie Programming Techniques
43
Component diagrams
System component
physical elements like files, executables, etc.
A component diagram shows how system components relate to each other Difference between package diagram and component diagram
package diagram logical grouping of design elements component diagrams physical components
Component diagrams can be combined with deployment diagrams to show the physical location of components of the system
<<communication>> Client
Server
44
Component diagrams
<<Header>> Order.h <<includes >> <<Body>> Order.cpp
<<o-Code>> Order.o
Component
Dependent
45
Deployment diagrams
Show
the physical architecture of the system Show the configuration of run-time processing elements and the software components and processes located on them The configuration shows the nodes and communication associations Nodes are typically used to show computers, while communication associations show the network and protocols used to communicate between nodes
Nodes are shown as 3D cubes
Deployment diagrams
can show either types of machines or their names and / or the active components within the nodes
Prof. Ioan Salomie Programming Techniques
46
Deployment diagrams
DBserver:DEC salesDB
Sales syst
47