Ch5: Software Specification
2
Dynamic modeling using UML
Static models:
Dynamic models:
3
Interaction diagrams
Purpose of an interaction diagram:
Sequence diagrams
Collaboration diagrams:
4
Uses of interaction diagrams
Refinement of use cases
Understand system dynamics
5
Notation for sequence diagrams
Classifiers Objects (instances of classes) and classes.Arranged horizontally.Objects respond to messages by invocation of methods, while Classes respond to messages by invocation of static methods. Represented by a rectangleObjects have labels name: ClassName, where name is optionalObjects with no name are called anonymous objectsClasses have labels in the form ClassName
aStudent:Student :Seminar
6
Notation for sequence diagrams (contd..)
Actors:Communicate with objectsModeled using the stick figureActors initiate, take active part in usage scenariosLabeled by ActorName
7
Notation for sequence diagrams
LifelineDenotes the life of an object during a sequence.Contains an X at the point at which the object is removed from the memory.In languages such as C++, where memory needs to be managed by the programmer a destroy method needs to be calledDotted vertical line below the class/object.
8
Notation for sequence diagrams
Focus of control: Long narrow rectangle placed on top of a lifelineDenotes an object performing an action to fulfill a message
9
Notation for sequence diagrams
Message:Conveys information from one object to another, or from an actor toan object, or from object to an actor.Represented by a horizontal arrow.Source and the target of the method are objects, message label is the signature of the method invoked in response to the message.If either the source or target is human actor, then the message is labeled with a brief text describing the information being communicated.
Wish to enroll isEligible(aStudent)
10
Drawing sequence diagrams
Place actors, objects, and classes that participate in the interaction at the top of the diagram, across the X-axis.
Place messages the objects send and receive along the Y-axis, in order of increasing time from top to bottom.
11
Sequence diagrams (contd..)
Object lifeline:
Focus of control:
12
Basic sequence diagrams
Object1:Class1 Object2:Class2
Activations
Messages
Lifelines
13
Basic sequence diagrams (contd..)
Object1:Class1 Object2:Class2
Destroy
14
Basic sequence diagrams
Object1:Class1 Object2:Class2
Return values (optional)
15
Basic sequence diagrams
Object1:Class1 Object2:Class2
[Condition to exit]
Repetition or a loop is depicted as a rectangle.Condition to exit is placed at the bottom of the rectangle.
16
Basic sequence diagrams
Object1:Class1 Object2:Class2
Self Call
17
Basic sequence diagrams
Object1:Class1 Object2:Class2
Messages can be sent conditionallyConditions can also be depicted on the sequence diagrams
[Condition true]
[Condition false]
18
Sequence diagram: Example
:Computer :PrinterServer :Printer
Print(File)Print(file)
19
Sequence diagram: Example
:Computer :PrinterServer :Printer :Queue
Print(File)Print(file)
Store(File)
[Printer free]
[Printer busy]
20
Collaboration diagrams
Displays object interactions organized around objects and their links to one another.
Do not explicitly show the lifeline of an object
Can show both create and destroy message Do not show the focus of control explicitly
Each message’s sequence number can be an indicator Show how one object is linked to another
21
Collaboration Diagrams (contd..)
Objects: Rectangles containing object signature Object signature consists of object name: object class
•Object name optional, starts with a lower case letter
•Class name (mandatory), starts with an upper case letter
•Objects connected by lines
•Actor symbol may appear Messages:
Labeled like C and Java function calls
• Followed by round brackets, and can have parameters and return values
Are followed by an arrow to show direction Messages may be numbered, starting from 1
22
Collaboration diagrams
How to draw collaboration diagrams:
23
Collaboration diagrams: Example
:Computer
:PrinterServer
:Queue
:Printer
1: Print(file)
[Printer free]2. Print(file)
[Printer busy]3. Store(file)
24
Common uses
Use sequence diagrams to model flows of control by time ordering
Use collaboration diagrams to model flows of control by organization
25
Sequence & Collaboration Diagrams: Example
For an item to be purchased, the Sales Assistant enters the name of the item on the screen. The system finds the item, and then determinesthe total stock available. The system then displays the item. Draw anUML Sequence and Collaboration diagram for the above usage scenario.
26
Sequence Diagram
:ProcessOrderScreen :Item :StockItem
Name of ItemfindItem(ItemName)
getQuantity(itemNum)
Display Results
:SalesAssitant
27
Collaboration Diagram
:ProcessOrderScreen
:Item
:StockItem
1. Enter item name
2.findItem(itemName)
3.getQuantity(itemNum)