Lecture 6 - Lamar University

advertisement
Software Engineering,
CPSC-4360-01, CPSC-5360-01,
Lecture 6
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
1
Review of Last Lecture

Design:


Major activities during design phase.
Tools:


4/9/2015
Class Diagram.
Object Diagram.
CPSC-4360-01, CPSC-5360-01, Lecture 6
2
Overview of This Lecture

Class Diagram





Association Class, Reification
N-Ary Association
Qualified Association
Interface
Interactions diagrams





4/9/2015
Collaborations, classifier and association roles
Interaction diagrams, object creation and destruction
Role multiplicity and iterated messages
Multi-objects
Conditional messages, messages to self
CPSC-4360-01, CPSC-5360-01, Lecture 6
3
Where are we now?
Requirement
Analysis
Design
Implement

In depth look at the
relevant tools:


Class Diagram
Interaction Diagram
Test
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
4
Association: Review

Annotation for Association:
Multiplicity
Number of
instances
associated
4/9/2015
Association
Name
Description of
the relationship
CPSC-4360-01, CPSC-5360-01, Lecture 6
Role Name
The role of the
instance in the
relationship.
Represented as
reference name
5
Association: Review

Role names can also help to distinguish multiple
associations, or self association.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
6
Properties of Links

There are cases where information about the link
need to be kept.

Example:



4/9/2015
A student takes a module and gets a mark for it.
The mark only makes sense if we know the student
and the module.
The mark is not simply an attribute of either class.
CPSC-4360-01, CPSC-5360-01, Lecture 6
7
Association Class


Association Classes can be added.
Behave like a combination of both association and class:



Association: Can connect two classes.
Class: Allow attribute to be stored.
Syntax: dashed line between association and class icon.
Association
Class
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
8
Association Class Example

Example:

John took CPSC4360, and scored 25 marks.
CPSC4360 : Module
John: Student
:Takes
mark = 25


The Takes instance is uniquely defined by both
John:Student and CPSC4360:Module.
Follow Up:

4/9/2015
What if John retakes CPSC4360, and scored 99 marks?
CPSC-4360-01, CPSC-5360-01, Lecture 6
9
Reification


Another technique to capture association information
is reification.
Reification means “Replacing an association with a
Class”.
Apply Reification.
An intermediate
class is added
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
10
Reification Example

Draw an object diagram for the two examples given
previously:





John takes CPSC4360 and score 25
John retakes CPSC4360 and score 99
The reification has the property of allowing students to
take a module more than once, in case they failed first
time.
This property was not possible for previous slide, when
there is exactly one link between a student and a
module.
Question to ponder:

Is reification and association class the same?
Draw the Object Diagram before Lecture
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
11
Association Class Property



Association classes are classes …
So they can participate in associations.
Example: MarkSheet lists all students taking a module
with the marks they got.
Can participate in the relationship
just like a normal class
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
12
N-ary Association

Associations can connect more than two classes:

A 3-way association could be used to store marks.
Multiplicity at a given association end defines the number of
instances of the class at that end that can be linked to a tuple
of instances, one from each of the other ends of association.
Example: ‘*’ specifies that each pair of student and module
object can be linked to zero or more Attempt objects.


4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
13
Qualified Association


In the real world, “objects” are usually identified by a
unique value (also known as key).
Example:

University uses Matriculation Number to identify a student.
University
1
*
Student
matric : Integer
name : String

Problems:


4/9/2015
Is matric number unique? Is it represented as such?
How do we know the matric can be used as a key?
CPSC-4360-01, CPSC-5360-01, Lecture 6
14
Qualified Association

Syntax:



The key is known as a qualifier.
The qualifier is written in a square box attached to the
class used to identify the other party.
The multiplicity is changed to reflect the relationship with
the qualifier instead of the class.
1
University
matric:Integer
0..1
Student
Name : String
Changed
Multiplicity
Qualifier
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
15
Qualified Association

Semantics:

The set of qualifiers is unique in the context of the
attached class:


The multiplicity reflects the relationship between the
identified class and the qualifier:


4/9/2015
E.g., the University has a set of unique matric values.
E.g., a Student is given exactly one matric in the University.
E.g., an University object will use matric to uniquely identify
zero or one Student (why zero?).
CPSC-4360-01, CPSC-5360-01, Lecture 6
16
Qualified Association: Example

Draw an object diagram to show:


A student John in LU university with matric. no. 007.
A student Helen in LU university with matric. no. 1234.
:Student
LU: University
007
Name = John
1234
:Student
Name = Helen
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
17
Interface


An interface in UML is a named set of operations.
Interfaces are used to characterize the behaviour of
an entity.

shown as a stereotyped class:
<<interface>>
List
Add( )
isEmpty( )
…

Generalization can be defined between interfaces.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
18
Realizing an Interface

A class realizes an interface if it provides
implementations of all the operations.


Similar to the implements keyword in Java.
UML provides two equivalent ways of denoting this
relationship:
<<interface>>
List
CircularLinkedList
CircularLinkedList
List

4/9/2015
Both represent “CircularLinkedList implements all
operations defined by the List interface”.
CPSC-4360-01, CPSC-5360-01, Lecture 6
19
Interface Dependency

A class can be dependent on an interface.
 This means that it makes use of the operations defined in
that interface.
 E.g., the Restaurant class makes use of the List interface:
Restaurant
<<use>>
List
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
20
Interface Dependency

If the class realizing the interface is known, the
dependency can be specified by:
Restaurant
<<use>>
CircularLinkedList
List

This information can also be attached to the role name
(known as the interface specifier):
CircularLinkedList
4/9/2015
bookingList : List
CPSC-4360-01, CPSC-5360-01, Lecture 6
Restaurant
21
Evolution of Class Diagram

Class Diagram evolves with the development
process:

Starts out as a Domain Model:


Refined to an Analysis Class Model:


Classes with name, attribute and simplified operation.
Refined to a Design Class Model:


4/9/2015
Classes with name and attribute only.
Classes with name, attribute and operation.
Type information and Scope defined for attribute and
operation.
CPSC-4360-01, CPSC-5360-01, Lecture 6
22
Interaction Diagrams
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
23
Interaction Diagrams



When a system is running, objects interact by
passing messages.
The messages define the system’s behaviour,
but they are not shown on static diagrams
(such as class diagrams).
UML defines two types of diagram for showing
interactions:


4/9/2015
collaboration diagram.
sequence diagram.
CPSC-4360-01, CPSC-5360-01, Lecture 6
24
Using Object Diagram: Interaction


A message can be added to an Object Diagram.
Syntax :


An arrow with message name and parameter (
)
Example:

The Bank performs “Fund Transfer” by withdrawing from one
account, and deposit to another account.
message
Object Diagram with Message
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
25
Problems with Object Diagrams

Object diagrams show a specific scenario:

They show specific objects, not the general case:


They show a fixed number of objects and links:


Can we withdraw from a1 and deposit into a1 again (for
whatever reason)?
They cannot show alternative functionality:


Can we withdraw from a2 and deposit in a1 instead?
What if the withdraw causes overdraft in a1? Can we
proceed with the deposit?
In a nutshell, we need something more general.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
26
Solution to this Problem



A more general method is needed to specify
behaviour.
Collaborations in UML in general do not show
individual objects, but rather the roles that
objects can play in the interaction.
An object diagram used to illustrate a
collaboration is known as a collaboration
instance set.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
27
Classifier Roles

Define collaborations using classifier roles:



Represent any object of a class.
Can have a name describing the role.
Syntax:
object_name /role_name : base_class
Collaboration Diagram
• Specify that any object of Account class can be substituted.
• “/Debtor” describes that money is taken out from this account.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
28
Classifier Role

Syntax Guide:



The classifier role is not underlined, to distinguish
from the object diagram usage.
The object_name can be used to label a classifier
role instead of a role name, when the role is not
clear/ not important.
The Object Diagram on Slide 25 is a
collaboration instance set of the Collaboration
Diagram on Slide 28:


4/9/2015
Substitute an object a1 for the /Debtor role.
Substitute an object a2 for the /Creditor role.
CPSC-4360-01, CPSC-5360-01, Lecture 6
29
Roles and Objects


Objects can play different roles in interactions.
An object can be substituted for a role if:



it is an instance of the base class of the role
or one of its subclasses.
In a given interaction, an object playing a
particular role will not normally make use of all
the features provided by the base class of the
role:

4/9/2015
E.g., an Account object in the /Debtor role will only
receive “withdraw()” message, but not “deposit()”
message.
CPSC-4360-01, CPSC-5360-01, Lecture 6
30
Association Role


Similar to Classifier Role, an Association Role
generalizes the links in the Object Diagram.
An association role connecting two classifier
roles indicates that objects playing those
roles:



Can establish links to each other.
Can exchange messages during interactions.
Question:

4/9/2015
What are the possible ways to set up a
communication (link) between two objects?
CPSC-4360-01, CPSC-5360-01, Lecture 6
31
Association Stereotypes

There are five ways to establish a link between two
objects:






Base Association
Parameter
Local Instantiation
Global Variable
Self-directed Link
In UML, five corresponding stereotypes are used to
denote the above:





<<Association>>
<<Parameter>>
<<Local>>
<<Global>>
<<Self>>
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
32
Association Role: Base Association



The most common kind of association.
The association is defined between the corresponding
classes (i.e., show up in the class diagram).
More “permanent” compared to other kind of association.


Syntax:


Usually kept as an attribute in the class.
Label the association role with stereotype <<Association>>.
Example:
Class Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
33
Base Association: Example
<<Association>>
<<Association>>
Collaboration Diagram


The interaction is possible because the Bank object
holds the “IsHeldAt ” to the two account objects.
As this is the most common case, the
<<association>> stereotype is usually omitted.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
34
Association Role: Parameter





One object is passed to another as a parameter of a
message.
In programming languages, this is implemented by
passing a reference to the object.
The object receiving the message knows the identity of
the parameter object, and can, in the method body,
send messages to that object.
This link is temporary, being available while the
operation is executing.
Syntax:

Label with the stereotype <<parameter>>.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
35
Parameter: Example
class A {
//No association to class B
void methodA(B objB){
objB.methodB( );
}
}


methodB( )
:A
<<parameter>>
:B
During the execution of
methodA(), an object of
class A can pass a
message to an object
of class B, because the
reference is passed as
parameter.
When methodA()
terminates, the link will
be over.
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
36
Association Role: Local Instantiation




Implementations of operations can create
local instances of any class.
Sending messages to these objects during the
execution of the operation is now possible.
A link corresponding to a local variable only
lasts for the duration of an operation call.
Syntax:

4/9/2015
Label with the stereotype <<local>>.
CPSC-4360-01, CPSC-5360-01, Lecture 6
37
Local Instantiation: Example
class A {
//No association to class B
void methodA( ){
B objB = new B();
objB.methodB( );
}
}


:A
methodB( )
<<local>>
:B
During the execution of
methodA(), an object of
class A can pass a
message to an object of
class B, because a local
object is created.
When methodA()
terminates, the link will
be gone.
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
38
Association Role: Global Variable


If any global variables exist and are visible, an
object can send messages to an object stored
in such a variable.
Example in Java:


Example in C++:


Nested class
Global object pointer
Syntax:

4/9/2015
Label with the stereotype <<global>>
CPSC-4360-01, CPSC-5360-01, Lecture 6
39
Global Variable: Example
class OuterA {
B objB;

class A { //Nested class
//No association to class B
void methodA( ){
objB.methodB( );
}
}
}
methodB( )
:A
<<global>>
Collaboration Diagram
4/9/2015
:B

During the execution of
methodA(), an object of
class A can pass a
message to an object
of class B, because an
attribute of the parent
class is accessible to all
nested classes.
When methodA()
terminates, the link
remains (why?).
CPSC-4360-01, CPSC-5360-01, Lecture 6
40
Association Role: Self-Directed



An object can always send messages to
itself, even though no explicit ‘link to self’ is
defined.
In programming languages, this capability is
provided by defining a pseudo-variable called
this or self.
Syntax:

4/9/2015
Label with the stereotype <<self>>.
CPSC-4360-01, CPSC-5360-01, Lecture 6
41
Self-Directed: Example
class A {
//No association to class A
void methodA( ){

this.methodA( );
}
}
:A

<<self>>
methodA( )
During the execution of
methodA(), an object of
class A can pass a
message to itself,
because a self
reference (this in Java)
is always available.
When methodA()
terminates, the link
remains.
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
42
Sequence Diagram: Review

Review sequence diagram introduced earlier in the
light of classifier role.
Classifier Role is
the more formal
description
Message
With parameter
Classifier
Role
Classifier
Role
Message ( Para )
Activation
Bar
Lifeline
Return value
Return
Control and
possibly value
are returned
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
Time
Passes
43
Sequence Diagrams



Show classifier roles only (no association roles).
The vertical dimension is the time and the messages
are drawn from top to bottom, in the order they are
sent.
Each role has a lifeline:



indicating the period of time during which objects playing
that role exist.
Syntax: vertical dashed line below the classifier role.
Messages are shown as arrows leading from the
lifeline of the message’s sender to that of the
receiver.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
44
Sequence Diagrams

The period of time during which an object is processing a
message is called activation.


When an object finishes processing a message, the control
returns to the sender of the message.


Syntax: narrow rectangle whose top is connected to a message.
Syntax: dashed arrow from the bottom of activation rectangle back to
lifeline of the role that sent the message.
The messages with solid arrowhead denote synchronous
messages, such as normal procedure calls (the object that
sends the message is suspended until the called object
returns the control to the caller).
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
45
Sequence Diagram: Simple Example

Suppose statements are to be printed for bank
accounts:

Bank passes the relevant Account to a Statement object for
printing.
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
46
Anything Missing?

The link between classifier roles is not indicated:




How can a statement object contacts the relevant account
object ?
You have to read the diagram carefully to deduce that the
link may be established by the parameter.
In some cases, such deductions are impossible/prone to
error when the information is not enough.
A Collaboration Diagram can show the same
exchange, but also includes the association role used
for communication.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
47
Collaboration Diagram


Show classifier and association roles.
Compared with diagram on Slide 46, messages also have:


sequence numbers to indicate order;
optional returned values with ‘:=’ notation.
Collaboration Diagram
Return
Value
Sequence
Number
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
48
Collaboration versus Sequence Diagrams



Unlike sequence diagrams, collaboration
diagrams show the association role.
Message sequencing cannot be shown
graphically and messages are numbered to
indicate the order in which they are sent.
Messages can be numbered sequentially, but
more commonly a hierarchical numbering
scheme is used (i.e., to reflect the nesting
activation made explicit in sequence diagrams).
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
49
Hierarchical Numbering



Within each activation, messages are numbered
sequentially starting from 1.
A unique label can then be generated for each
message by adding the number of the message
to the end of the number of the activation
sending the message.
Syntax: use a “.”


to separate the numbers and
to reflect that another level of nesting of control flow
has been initiated.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
50
Hierarchical Numbering. Example
1 : because it is the
first message
1.1: because it is the first
message sent during the
computation of message 1
1.2: because it is the second
message sent during the
computation of message 1
2.1.2: because it is the second
message sent during the
computation of message
2.1
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
51
Interaction Diagram: Additional
Notations

Subsequent examples illustrate the notations for:







Object Creation
Object Destruction
Iterated Messages
Multiobjects
Conditional Messages
Message to Self
Should take note of how to portrait certain interaction
in both Sequence Diagram (SD) and Collaboration
Diagram (CD).
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
52
Sequence Diagram: Object Creation

As time is explicitly represented in a sequence
diagram, the object creation is easy to draw:
:A
class A {
void methodA( ){
B objB = new B();
objB.methodB( );
}
}
B( )
:B
methodB( )
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
53
Collaboration Diagram: Object Creation

In a Collaboration Diagram, new objects and new
associations have to be labeled with {new}.
class A {
void methodA( ){
B objB = new B();
objB.methodB( );
}
}
:A
1: B( )
{new}
<<local>>
2: methodB( )
:B
{new}
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
54
Sequence Diagram: Object Destruction




In languages with automatic garbage collection (like
Java), you cannot explicitly delete an object.
Instead, remove all references to the object for it to be
collected.
Label the message as <<destroy>>.
Mark the lifeline of the destroyed object with a cross.
class A {
void methodA( ){
B objB = new B();
... ... ...
objB = null;
... ... ...
}
}
:A
:B
<<destroy>>
Sequence Diagram
Reminder: Only the circled part of code is represented.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
55
Collaboration Diagram: Object
Destruction

In a Collaboration Diagram:


Similarly, label the message as <<destroy>>.
Label the destroyed objects and links with {destroyed}.
class A {
void methodA( ){
B objB = new B();
... ... ...
objB = null;
... ... ...
}
}
:A
{destroyed}
<<local>>
1: <<destroy>>
:B
{destroyed}
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
56
Role Multiplicity


The number of objects playing a role can vary from one
occasion to another.
Example (Restaurant Case Study):

Looking for bookings for a particular date will depend on how
many total bookings are there.
: Restaurant
: Booking
getDate( )
Need to show “many
booking objects will
be involved”.
Return date
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
57
Role Multiplicity


Role multiplicity can be added to classifier role to indicate
the number of objects involved.
Syntax:

Same as the multiplicity notation in class diagram (e.g., 1..8, *,
2..* , etc).
: Booking *
: Restaurant
getDate( )
Role Multiplicity
Shows that zero or more
Booking objects will
be involved
Return date
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
58
Role Multiplicity


The notation is the same in both Sequence Diagram
and Collaboration Diagram.
However, the fact that the message is iterated is still
not represented.
: Booking *
: Restaurant
getDate( )
Sent Multiple times
Return date
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
59
Iterated Messages

We can clarify this by:
adding a multiplicity to the affected role.
specifying that the message is iterated.



Syntax:
Recurrence consists in ‘*’ written after the sequence number,
possibly followed by an iteration clause.
There is no formal syntax for iteration clause. Pseudo codelike condition is usually used, e.g., [i = 1 .. N] or [i = 1 to N].



Example:
Denote Recurrence
Denote the Recurrence Condition
1 *
[i = 1.. N] getDate( )
: Booking *
: Restaurant
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
60
Multiobject

A multiobject denotes a collection of objects:

It is a role with a multiplicity of zero or more.
: Booking
: Booking
: Restaurant
Denote
Multiobject
Collaboration Diagram

It implies an intermediate data structure, e.g.:
: Restaurant
: Vector
: Booking *
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
61
Property of Multiobject

Using multiobject prevents a premature
commitment to a particular data structure:




E.g., What if vector is not a good data structure for
this case?
Semantically, a multiobject is a single object
representing a collection of objects.
A single message sent to it implies an
operation involving the collection of objects.
A good example of such operation would be
looking for a particular object in the collection.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
62
Multiobject: Example

Assume that there is only one booking per date to simplify
the discussion:



A single message findBooking(Date) is sent to the Booking multiobject.
The multiobject inspects all its Booking object and returns the
appropriate booking B (to indicate that B is not a new object, but one
from the multiobject, a composition link is used).
The Restaurant stores B as a local reference for subsequent
operations.
:Restaurant
B := findBooking( Date )
<<local>>
{new}
: Booking
: Booking
B: Booking
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
63
Multiobject: Message for all objects



To send a message to all objects in the multiobject:
 Send a single message to the multiobject.
 The multiobject goes through some iterative process and
sends the message to each object in the collection.
By convention, such interactions can be abbreviated by
using iterative messages.
Iterated messages to a multiobject are understood to be
sent to individual objects.
Each booking in the
multiobject will receive the
Print( ) message
* Print( )
: Restaurant
: Booking
: Booking
Collaboration Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
64
Sequence Diagram: Conditional Message


Conditions can be added to messages to show
the situations when they are sent.
Syntax:
 Write the condition in [ ] preceding a message.
class A {
void methodA( ){
B objB = new B();
... ... ...
if ( x < y )
objB.methodB( );
}
}
:A
:B
[x < y] methodB( )
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
65
Collaboration Diagram: Conditional
Message

Same syntax can be used for a collaboration diagram.
class A {
void methodA( ){
B objB = new B();
... ... ...
if ( x < y )
objB.methodB( );
}
}
4/9/2015
[x < y] methodB( )
:A
CPSC-4360-01, CPSC-5360-01, Lecture 6
:B
Collaboration Diagram
66
Alternative Flows

Sequence diagrams can show alternative
message sequences in one diagram:





Two or more messages start at the same point
(fork).
They are distinguished by conditions (only one will
be sent).
Return messages come together later (join).
Objects that receive messages may need branching
lifelines to represent alternative possibilities.
Should draw two separate diagrams instead.
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
67
Sequence Diagram: Alternative Flow

Pay attention to:


Branching of the messages (Fork).
Joining of the return messages (Join).
class A {
void methodA( ){
B objB = new B();
... ... ...
if ( x < y )
objB.methOne( );
else
objB.methTwo( );
}
}
:B
:A
[x < y] methOne( )
[x >= y] methTwo( )
Sequence Diagram
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
68
Sequence Diagram: Message to Self


An object can send message to itself:
 Invoking another operation of its own.
Usually represents implementation details.
class A {
void methodA( ){
B objB = new B();
objB.methOne( );
}
}
:A
methOne( )
class B {
void methOne( ){
methTwo( );
}
void methTwo( ){
... ... ...
}
}
4/9/2015
:B
methTwo( )
Sequence Diagram
CPSC-4360-01, CPSC-5360-01, Lecture 6
69
Collaboration Diagram: Message to Self

Make use of the <<self>> stereotype for collaboration
diagram.
class A {
void methodA( ){
B objB = new B();
objB.methOne( );
}
}
:A
1: methOne( )
:B
<<self>>
class B {
void methOne( ){
methTwo( );
}
void methTwo( ){
... ... ...
}
}
4/9/2015
1.1: methTwo( )
Collaboration Diagram
CPSC-4360-01, CPSC-5360-01, Lecture 6
70
Summary

Class Diagram





Association Class, Reification
N-Ary Association
Qualified Association
Interface
Interactions diagrams





4/9/2015
Collaborations, classifier and association roles
Interaction diagrams, object creation and destruction
Role multiplicity and iterated messages
Multi-objects
Conditional messages, messages to self
CPSC-4360-01, CPSC-5360-01, Lecture 6
71
Where are we now?
Requirement
Analysis

Topics Covered:

Design


Implement

Detailed Class Diagram
Object Diagram
Collaboration Diagram
Sequence Diagram
Test
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
72
Reading Suggestions


Chapter 5 of [Bimlesh, Andrei, Soo; 2007]
Chapters 8 and 9 of [Priestley; 2004]
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
73
Coming up next


Chapter 6 of [Bimlesh, Andrei, Soo; 2007]
Chapter 10 of [Priestley; 2004]
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
74
Thank you for your attention!
Questions?
4/9/2015
CPSC-4360-01, CPSC-5360-01, Lecture 6
75
Download