Behavioral Modeling - PowerPoint PPT Presentation

1 / 67
About This Presentation
Title:

Behavioral Modeling

Description:

In Visio, you should add the methods (operations) to your classes (from your ... More Visio Hints. Before drawing Sequence or ... Visio does this automatically ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 68
Provided by: evans9
Category:

less

Transcript and Presenter's Notes

Title: Behavioral Modeling


1
Behavioral Modeling
  • Chapter 8
  • Prepared by Evans Adams
  • January 2003

2
Behavioral Modeling
  • Describe the internal dynamic aspects of an
    information system that support the business
    processes
  • Analysis Phase
  • Describe what the dynamic view of the system is
  • Without specifying how the processes are to be
    implemented.
  • Design and Implementation Phases
  • Details of the operations (methods) contained in
    the objects are fully specified.
  • UML models used in behavioral modeling
  • Sequence Diagrams,
  • Collaboration Diagrams, and
  • Statechart Diagrams

3
Behavioral Modeling
  • There are two types of Behavioral Models.
  • Models used to represent the underlying details
    of a business process portrayed by a use case
    model.
  • UML uses Interaction Diagrams
  • Sequence Diagrams
  • Collaboration Diagrams
  • Models used to represent the changes that occur
    in the underlying data (or Objects).
  • UML uses Statechart Diagrams

4
Behavioral Models
  • Depict the internal view of the Business
    Process that a Use Case describes by showing
  • The interaction that takes place between the
    objects that collaborate to support a use case
  • Through the use of interaction (sequence and
    collaboration) diagrams.
  • The effect that a set of use cases has on the
    objects in the system
  • Through the use of Statechart Diagrams

5
Behavioral Models
  • As the behavioral models are created,
  • Analysts often make changes to the use cases and
    structural models
  • To reflect new information gathered during the
    behavioral modeling process

6
Interaction Diagrams
  • Class Diagrams (previous Chapter)
  • Describe Structure
  • Focus Is at the Class Level
  • The Interaction Diagrams
  • Describe Behavior
  • Focus on the Object Level

7
Interaction Diagram Components
  • Objects
  • Operations
  • Messages

8
Sequence Diagrams
  • Illustrate
  • the objects that participate in a use case and
  • the sequence of messages that pass between them
    over time
  • for one use case (or one use case scenario).
  • Are very helpful for understanding
  • Real-time Specifications and
  • Complex Use Cases.

9
Sequence Diagrams
  • Generic Sequence Diagram
  • Shows all possible scenarios for a use case,
  • A set of Instance Sequence Diagrams
  • each of which depicts a single scenario within
    the use case.
  • Used by Analysts to understand the flow of
    control of a scenario by time
  • Scenario
  • A single executable path through a use case.

10
Sequence Diagram Syntax
AN ACTOR AN OBJECT A LIFELINE A FOCUS OF
CONTROL A MESSAGE OBJECT DESTRUCTION
anObjectaClass
aMessage()
x
11
Example Sequence Diagram
12
Elements of a Sequence Diagram
  • Actors and Objects are placed across the top of
    the diagram using
  • actor symbols, from the use case diagram,
  • object symbols, from the Class or Object diagram
  • For each of the objects, the name of the class
    that they are an instance of is given after the
    object's name
  • In Visio, you should add the methods (operations)
    to your classes (from your Class Diagrams) before
    drawing Sequence and Interaction Diagrams

13
More Visio Hints
  • Before drawing Sequence or Collaboration
    Diagrams
  • Draw a Class Diagram (if you do not have one)
  • Draw a Use Case Diagram (if you do not have one)
    for your Actors
  • Identify all methods which will appear on the
    Sequence or Collaboration Diagram for the
    appropriate class (you do not need to define data
    members at this time)
  • You can then create objects from those classes
    and invoke their methods
  • When you need new method, first add it to the
    appropriate class (this automatically updates
    your class diagram)
  • Failure to follow these hints will add
    unnecessary complications to your task

14
Elements of a Sequence Diagram
  • Lifeline
  • A dotted line that runs vertically below each
    actor and object
  • An X is placed at the end of the lifeline at the
    point that a temporary object is destroyed (not
    supported in Visio)
  • Otherwise the object persists after the Scenario
    ends

15
Elements of a Sequence Diagram
  • Focus of Control
  • A thin rectangular box overlaid onto the lifeline
    to show when the classes are sending and
    receiving messages
  • A message is a communication between classes that
    conveys information with the expectation that
    activity will ensue
  • Links
  • Solid lines connecting two objects when messages
    are passed
  • The arrow on the link shows which way the message
    is being passed
  • Any argument values for the message are placed in
    parentheses next to the messages name.

16
Elements of a Sequence Diagram
  • The order of messages goes from the top to the
    bottom of the page
  • so messages located higher on the diagram
    represent messages that occur earlier on in the
    sequence,
  • versus the lower messages that occur later

17
Elements of a Sequence Diagram
  • There are times that a message is only sent if a
    condition is met.
  • In those cases, the condition is placed between a
    set of and before the message name
  • e.g., aPatient Exists LookupBills().
  • Visio calls this a constraint
  • Repeating a Message
  • Use an in front of the message name,
  • e.g., Request CD.

18
Elements of a Sequence Diagram
  • Self-delegation
  • An object sends a message to itself.
  • Return Link
  • a dashed message indicates the return from a
    message
  • Should only be used
  • when they add a lot of information to the diagram
  • Since they tend to clutter a diagram

19
Elements of a Sequence Diagram
  • When an object creates another object
  • the create object message is sent directly to an
    object instead of its lifeline.
  • Visio does not support this
  • Need to send the create object message to the
    lifeline in Visio
  • In Figure 8-1, the actor aReceptionist creates an
    object anAppt

20
Building a Sequence Diagram
  • Set the context.
  • Identify which objects will participate.
  • Set the lifeline for each object.
  • Add the focus of control to each object's
    lifeline.
  • Layout the messages from the top to the bottom of
    the diagram based on the order in which they are
    sent.
  • Validate the sequence diagram.

21
Set the Context
  • The context of the diagram can be
  • a system,
  • a use case,
  • a scenario of a use case, or
  • an operation of a class.
  • Most commonly, the context is one use case
    scenario.

22
Set the Context (Example)
  • We want to create an Instance Sequence Diagram
    for the Create New Appointment Scenario in the
    Make Appointment Use Case
  • See Figure 6-1 (next slide)

23
Figure 6-1 Make Appointment Use Case
Normal Flow of Events 1.    The Patient contacts
the office regarding an appointment. 2.    The
Patient provides the Receptionist with their name
and address. 3.    The Receptionist validates
that the patient exists in the Patient
database. 4.    The Receptionist executes the
Make Payment Arrangements use case. 5.    The
Receptionist asks Patient if he or she would like
to make a new appointment, cancel an existing
appointment or change an existing
appointment. If the patient wants to make a new
appointment, the S-1 new appointment subflow
is performed. If the patient wants to cancel
an existing appointment, the S-2 cancel
appointment subflow is performed. If the
patient wants to change an existing appointment,
the S-3 change appointment subflow is
performed. The Receptionist provides the results
of the transaction to the Patient.
24
Figure 6-1 Make Appointment Use Case
SubFlows S-1 New Appointment 1.    The
Receptionist asks the Patient for possible
appointment times. 2.    The Receptionist matches
the Patient's desired appointment times with
available dates and times and schedules the new
appointment. S-2 Cancel Appointment 1.    The
Receptionist asks the Patient for the old
appointment time 2.    The Receptionist finds the
current appointment in the appointment file and
cancel it. S-3 Change Appointment 1.    The
Receptionist performs the S-2 cancel appointment
subflow. The Receptionist performs the S-1 new
appointment subflow
Alternate/Exceptional Flows 3a The
Receptionist executes the Create New Patient use
case. S-1, 2a1 The Receptionist proposes some
alternative appointment times based on what is
available in the appointment schedule. S-1,
2a2 The Patient chooses one of the proposed
times or decides not to make an appointment.
25
Identify The Objects
  • The Use Case Scenario should refer to the
    relevant classes / objects
  • It is likely that new classes, and hence new
    objects, will be uncovered.
  • Don't worry too much about identifying all the
    objects perfectly
  • Remember the behavioral modeling process is
    iterative.
  • Plan to Throw One Away, You Will Anyway!

26
Identify The Objects (Example)
  • The Class Diagram is referenced and modified
    according to new classes and methods which are
    identified in the process of creating the
    Sequence Diagram.
  • See Class Diagram (Figure 7-2) next slide

27
Example Class Diagram
28
Set the Lifeline for Each Object
  • Draw a vertical dotted line below each object
  • to represent the objects existence during the
    sequence
  • Visio does this automatically
  • An X should be placed below the object at the
    point on the lifeline where the object goes out
    of existence (not support in Visio)

29
Add Focus of Control
  • Draw a narrow rectangle box
  • over top of the lifelines
  • to represent when the classes are sending and
    receiving messages.

30
Layout the Messages
  • Draw arrows to represent the messages being
    passed from object to object,
  • with the arrow pointing in the message's
    transmission direction
  • Place the arrows in order
  • from the first message (at the top)
  • to the last (at the bottom)
  • to show time sequence.
  • Parameters should be placed in parentheses
  • If a message is expected to be returned as a
    response to a message,
  • then the return message is not explicitly shown
    on the diagram.

31
Completed Sequence Diagram
32
Validate the Sequence Diagram
  • To guarantee that the sequence diagram
  • completely represents the underlying process(es)
  • for its Use Case Scenario
  • Validate Names with the Use Case Scenario and the
    Class Diagram
  • Make the required modifications to the Use Case
    Scenario and the Class Diagram

33
CD Selections Example
  • Discuss Derivation of Sequence Diagram in Figure
    8-5 from
  • the Places Order Use Case (Figure 8-4)
  • The CD Selections Class Diagram (Figure 7-12)

34
Places Order Use Case
Normal Flow of Events 1. Customer submits a
search request to the system. 2. The system
provides the customer a list of recommended
CDs. 3. The customer chooses one of the CDs to
find additional information. 4. The system
provides the customer with basic information
CD Reviews 5. The customer calls the maintain
order use case. 6. The customer iterates over 3
through 5 until finished shopping. 7. The
customer executes the checkout use case. 8. The
customer leaves the website.
35
CD Selections Class Diagram
36
CD Selections Sequence Diagram
37
Collaboration Diagrams
  • Essentially an object diagram that shows message
    passing relationships instead of aggregation or
    generalization associations.
  • Emphasize the flow of messages among objects,
    rather than timing and ordering of messages

38
Collaboration Diagrams
  • Equivalent to Sequence Diagrams
  • emphasize the flow of messages through a set of
    collaborating objects,
  • while the sequence diagrams focus on the time
    ordering of the messages being passed.
  • Analysts often use both to more fully understand
    the dynamic activity of the system.

39
Collaboration Diagram Syntax
AN ACTOR AN OBJECT AN ASSOCIATION A
MESSAGE
anObjectaClass
40
Example Collaboration Diagram
41
Collaboration Diagram Elements
  • Actors and Objects
  • that collaborate to execute the use case
  • are placed on the collaboration diagram
  • in a manner to emphasize the message passing that
    takes place between them.
  • Differences from Sequence Diagram,
  • Does not have a means to explicitly show an
    object being deleted or created.
  • Never shows returns from message sends while the
    sequence diagram can optionally show them.

42
Collaboration Diagram Elements
  • An association is shown between actors and
    objects with an undirected line.
  • Messages are shown as labels on the associations.
  • Included with the labels are lines with arrows
    showing the direction of the message being sent.
  • Sequence numbers indicate the order in which
    messages are sent.
  • Conditional Messages are same as on sequence
    diagram
  • An placed after the sequence number indicates
    message is sent repeatedly

43
Collaboration Diagram Elements
  • An association that loops onto an object shows
    self-delegation.
  • The message is shown as the label of the
    association.
  • Collaboration Diagrams can be simplified through
    the use of packages
  • objects are grouped together (based on the
    messages sent to and received from other objects)
    into packages

44
Building a Collaboration Diagram
  • Set the context
  • Identify which objects (actors) and the
    associations between the objects that participate
    in the collaboration.
  • Layout the collaboration diagram.
  • By placing the objects together based on the
    associations that they have with the other
    objects in the collaboration.
  • Add messages.
  • Add the name and sequence number of the
    message(s) to the association link between the
    objects
  • And an arrow showing the direction the message is
    being sent.
  • Validate the collaboration diagram.

45
Figure 8-10 Collaboration Diagram for the
Places Order Use Case (corresponds to Sequence
Diagram in Figure 8-5)
46
Statechart Diagrams
  • A dynamic model that shows
  • the different states that a single object passes
    through during its life in response to events,
  • along with its responses and actions.
  • Further define complex objects to help simplify
    the design of algorithms for their methods.

47
Statechart Diagrams
  • Shows the different states of the object and what
    events cause the object to change from one state
    to another.
  • Should be used
  • if you are interested in understanding the
    dynamic aspects of a single class and how its
    instances evolve over time,
  • and not with how a particular use case scenario
    is executed over a set of classes (use
    Interaction Diagrams for this)

48
Components of Statechart Diagrams
  • States
  • Events
  • Transitions
  • Actions
  • Activities

49
Statechart Theory
  • The state of an object is defined by
  • The value of its attributes and
  • its relationships with other objects at a
    particular point in time.
  • For example, a patient might have a state of
    "new" or "current" or "former."
  • The attributes or properties of an object affect
    the state that it is in however, not all
    attributes or attribute changes will make a
    difference.

50
Statechart Theory
  • An event is
  • Something that takes place at a certain point in
    time and
  • changes a value(s) that describes an object,
  • which in turn changes the objects state.
  • It can be
  • a designated condition becoming true,
  • the receipt of the call for a method by an
    object, and
  • the passage of a designated period of time.
  • The state of the object determines exactly what
    the response to an event will be.

51
Statechart Theory
  • A transition is
  • A relationship that represents the movement of an
    object from one state to another state.
  • Some transitions will have a guard condition.
  • A guard condition is a Boolean expression
  • which allows a transition to occur only if the
    condition is true.
  • An object typically moves from one state to
    another based on the outcome of an action that is
    triggered by an event

52
Statechart Theory
  • An action is
  • an atomic, non-decomposable process
  • than can not be interrupted.
  • From a practical perspective,
  • actions take zero time and
  • they are associated with a transition.

53
Statechart Theory
  • An activity is
  • A non-atomic, decomposable process
  • that can be interrupted.
  • Activities
  • Take some period of time to complete,
  • Can be started and stopped by an action, and
  • Are associated with states.

54
Elements of a Statechart Diagram
  • A state
  • Is a set of values that describe an object at a
    specific point in time, and
  • It represents a point in an objects life in
    which it
  • satisfies some condition,
  • performs some action, or
  • waits for something to happen

55
Elements of a Statechart Diagram
  • A state is depicted by a state symbol,
  • which is a rectangle with rounded corners with a
    descriptive label that communicates a particular
    state.
  • There are two exceptions.
  • An initial state is shown using a small solid
    filled circle, and
  • A final state is shown as a circle surrounding a
    small solid filled in circle.
  • These exceptions depict when an object begins and
    ceases to exist, respectively.
  • VA does not have initial and final state symbols
  • VA calls these State Transition Diagrams

56
Elements of a Statechart Diagram
  • Arrows
  • are used to connect the state symbols,
  • representing the transitions between states.
  • Each arrow is labeled with
  • the appropriate event name, and
  • any parameters or conditions that may apply.

57
Statechart Diagram Syntax
A STATE AN INITIAL STATE A FINAL
STATE AN EVENT A TRANSITION
aState
anEvent
58
Example Statechart Diagram
59
Building a Statechart Diagram
  • Statechart diagrams are drawn to depict a single
    class from a class diagram.
  • Typically the classes are
  • very dynamic and complex,
  • requiring a good understanding of
  • their states over time and
  • events triggering changes.
  • Analysts typically identify which classes will
    need to undergo a complex series of state changes
    and draw a Statechart diagram for each of them

60
Building a Statechart Diagram
  • Set the context.
  • Identify the initial, final, and stable states of
    the object.
  • Note VA does not have special symbols for
    initial and final states
  • Determine the order in which the object will pass
    through the stable states.
  • Identify the events, actions, and guard
    conditions associated with the transitions.
  • Validate the statechart diagram.

61
CD Selections Statechart Example
  • The Order Class from the Place Order Use Case may
    be complex enough to merit drawing a Statechart
    Diagram
  • User Interviews reveal the Life Cycle in Figure
    8-12 for an Order

62
Order Object Life Cycle (Fig 8-14)
  • The customer creates an order on the Web
  • The customer submits the order once he or she is
    finished
  • The credit authorization needs to be approved for
    the order to be accepted
  • If denied, the order is returned to the customer
    for changes or deletion
  • If accepted, the order is placed
  • The order is shipped to the customer
  • The customer receives the order
  • The order is closed

63
CD Selections Statechart Example
  • Based on the Order Life Cycle, the stable states
    shown on Figure 8-15 were identified
  • The events, actions and guard conditions are
    added to the diagram based upon the Order Life
    Cycle
  • The diagram is validated with the users

64
CD Selections
65
Summary
  • Sequence diagrams illustrate the classes that
    participate in a use case and the messages that
    pass between them.
  • Collaboration diagrams provide a dynamic view of
    the object-oriented system and accentuate message
    passing between collaborating actors and objects.
  • Statechart diagrams show the different states
    that a single class passes through in response to
    events.

66
Expanding the Domain
  • Each year the Association for Computing Machinery
    (ACM) sponsors a conference on object oriented
    programming. For details about future
    conferences and other ACM programs check
  • http//oopsla.acm.org
  • http//www.acm.org

67
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com