Lecture11 2up
Lecture11 2up
Chapter 8:
Modelling Interactions and Behaviour
Lecture 11
546
Interactions and messages
547
• Instances of classes
—Shown as boxes with the class and object identifier
underlined
• Actors
—Use the stick-person symbol as in use case diagrams
• Messages
—Shown as arrows from actor to object, or from object to
object
548
Creating interaction diagrams
549
550
Sequence diagrams
551
Sequence diagrams –
same example, more details
552
Sequence diagrams –
an example with replicated messages
• An iteration over objects is indicated by an asterisk preceding the
message name
553
Sequence diagrams –
an example with object deletion
• If an object’s life ends, this is shown with an X at the end of the lifeline
554
Communication diagrams – an example
555
Communication diagrams
556
Communication diagrams –
same example, more details
557
Communication links
558
Other communication links
559
560
How to choose between using a sequence
or communication diagram
Sequence diagrams
• Make explicit the time ordering of the interaction.
—Use cases make time ordering explicit too
—So sequence diagrams are a natural choice when you build
an interaction model from a use case.
561
562
Communication diagrams and patterns
563
564
State diagrams – an example
565
States
• Special states:
—A black circle represents the start state
—A circle with a ring around it represents an end state
566
Transitions
• The label on each transition is the event that causes the change
of state.
567
568
State diagrams – an example with
conditional transitions
569
570
State diagram – an example with activity
571
572
State diagram – an example with actions
573
574
Nested substates and guard conditions
575
576
8.3 Activity Diagrams
• An activity diagram
—Can be used to understand the flow of work that an object or
component performs.
—Can also be used to visualize the interrelation and interaction between
different use cases.
—Is most often associated with several classes.
577
578
Representing concurrency
579
Representing concurrency
580
Swimlanes
581
582
8.4 Implementing Classes Based on
Interaction and State Diagrams
• You should use these diagrams for the parts of your system
that you find most complex.
—I.e. not for every class
583
Example: The CourseSection class
States:
• ‘Planned’:
closedOrCancelled == false && open == false
• ‘Cancelled’:
closedOrCancelled == true &&
registrationList.size() == 0
585
States:
• ‘Open’ (accepting registrations):
open == true
586
Example: The CourseSection class
587
"
588
Example: The CourseSection class
public void closeRegistration()
{
// to 'Canceled' or 'Closed' state
open = false;
closedOrCanceled = true;
if (registrationList.size() < course.getMinimum())
{
unregisterStudents(); // to 'Canceled' state
}
}
"
590
Example: The CourseSection class
// Private method to remove all registrations
// Activity associated with 'Canceled' state.
private void unregisterStudents()
{
for(Registration next : registrationList)
{
next.unregisterStudent();
registrationList.remove(next);
}
}
// Called within this package only, by the constructor of
// Registration to ensure the link is bi-directional
void addToRegistrationList(Registration newRegistration)
{
registrationList.add(newRegistration);
}
}
591
592