csci-383 object-oriented programming & design lecture 12

22
CSCI-383 Object-Oriented Programming & Design Lecture 12

Upload: kelly-gilmore

Post on 13-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSCI-383 Object-Oriented Programming & Design Lecture 12

CSCI-383

Object-Oriented Programming & Design

Lecture 12

Page 2: CSCI-383 Object-Oriented Programming & Design Lecture 12

UML Diagrams

Page 3: CSCI-383 Object-Oriented Programming & Design Lecture 12

Interaction Diagrams

• Interaction diagrams are used to model the dynamic aspects of a software system– They help you to visualize how the system runs– An interaction diagram is often built from a use case and a

class diagram– The objective is to show how a set of objects accomplish

the required interactions with an actor

Page 4: CSCI-383 Object-Oriented Programming & Design Lecture 12

Interactions and Messages

• Interaction diagrams show how a set of actors and objects communicate with each other to perform– The steps of a use case, or– The steps of some other piece of functionality

• The set of steps, taken together, is called an interaction

• Interaction diagrams can show several different types of communication– E.g. method calls, messages send over the network– These are all referred to as messages

Page 5: CSCI-383 Object-Oriented Programming & Design Lecture 12

Elements Found in Interaction Diagrams

• 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

Page 6: CSCI-383 Object-Oriented Programming & Design Lecture 12

Creating Interaction Diagrams

• You should develop a class diagram and a use case model before starting to create an interaction diagram

• There are two kinds of interaction diagrams: – Sequence diagrams– Communication diagrams

Page 7: CSCI-383 Object-Oriented Programming & Design Lecture 12

Sequence Diagrams

Class Diagram

Sequence Diagram

Page 8: CSCI-383 Object-Oriented Programming & Design Lecture 12

Sequence Diagrams

• A sequence diagram shows the sequence of messages exchanged by the set of objects performing a certain task – The objects are arranged horizontally across the diagram– An actor that initiates the interaction is often shown on the left – The vertical dimension represents time – A vertical line, called a lifeline, is attached to each object or actor – The lifeline becomes a broad box, called an activation box during the

live activation period– A message is represented as an arrow between activation boxes of

the sender and receiver• A message is labelled and can have an argument list and a return value

Page 9: CSCI-383 Object-Oriented Programming & Design Lecture 12

Sequence Diagrams

Same example but with more details

Page 10: CSCI-383 Object-Oriented Programming & Design Lecture 12

Sequence Diagrams

• If an object’s life ends, this is shown with an X at the end of the lifeline

Page 11: CSCI-383 Object-Oriented Programming & Design Lecture 12

Exercise

Suppose that we are developing a loan processing system and we have identified the following use case:

Use case: Submit Loan RequestActors: Applicant, Credit Bureau

Steps:1. An applicant completes and submits a loan application to the bank

via the Internet.2. The system validates the information on the loan application, checking that it is correct and as complete as possible.3. The system forwards a loan request to an external credit bureau for a

credit report on the applicant.4. The system calculates the applicant’s credit score based on the

returned credit report.

Draw a corresponding sequence diagram (DONE IN CLASS)

Page 12: CSCI-383 Object-Oriented Programming & Design Lecture 12

UML Diagrams

Page 13: CSCI-383 Object-Oriented Programming & Design Lecture 12

State Diagrams

• State diagrams are a technique to describe the behavior (i.e., state changes) of a single object according to events and messages which the object sends and receives

• How does an individual object interact with other objects?– Reacting to events and to messages received by the object– Triggering actions and sending messages to other objects

Page 14: CSCI-383 Object-Oriented Programming & Design Lecture 12

State Diagrams

• State diagrams are good at describing the behavior of an individual object across several use cases

• Draw state diagrams especially for classes that are not well understood and that need detailed description

• State diagrams are not very good at describing behavior that involves a number of objects collaborating together

• If you have to describe several objects, which are involved in a single use case, use interaction diagrams instead

Page 15: CSCI-383 Object-Oriented Programming & Design Lecture 12

States

• A state– Represents the internal condition/state of an object for a

certain period of time– Corresponds to an interval of time between 2 events

• The response to events may depend on the state of an object

• Object creation comes together with an initial object state

• Object deletion may be related with (one or many) final states

Page 16: CSCI-383 Object-Oriented Programming & Design Lecture 12

Sample State Diagram

Page 17: CSCI-383 Object-Oriented Programming & Design Lecture 12

Events

• An event is something worth noticing at a point of time– A signal from one object to another (e.g., “delivered”)– A message received by an object (e.g., “check item”)– A certain date/time (e.g., “after 10 seconds” of being in a

certain state or “at 31-dec-2000, 00:00”)

• Events may take arguments (e.g., “deliver to receiver: Customer”)

Page 18: CSCI-383 Object-Oriented Programming & Design Lecture 12

Transitions

• A transition represents a change of the internal condition/state of an object

• A transition is usually triggered (“fired”) by an event. Transitions without event label (“lambda transitions”) fire immediately

• Transitions fire instantly– From exactly one state to another state or to itself (self-

transition) and are not interruptible

Page 19: CSCI-383 Object-Oriented Programming & Design Lecture 12

Transitions

Page 20: CSCI-383 Object-Oriented Programming & Design Lecture 12

Guards

• A guard is a logical condition (i.e., value is either “true” or “false”)

• A guarded transition fires only if the guard resolves to “true”

• Since only one transition can be fired in a given state, guards are intended to be mutually exclusive for any event

• Events may be guarded

Page 21: CSCI-383 Object-Oriented Programming & Design Lecture 12

Guards

Page 22: CSCI-383 Object-Oriented Programming & Design Lecture 12

Exercise

Draw a state diagram that shows the behavior of instances of the CourseSection class in the following class diagram:

(DONE IN CLASS)