Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 18: Object-Oriented Design – Interaction and State Diagrams Anita S. Malik Adapted from Schach (2004) Chapter 12.

Similar presentations


Presentation on theme: "Lecture 18: Object-Oriented Design – Interaction and State Diagrams Anita S. Malik Adapted from Schach (2004) Chapter 12."— Presentation transcript:

1 Lecture 18: Object-Oriented Design – Interaction and State Diagrams Anita S. Malik anitamalik@umt.edu.pk Adapted from Schach (2004) Chapter 12

2 CS540 Software Design 2Lecture 18 Capturing System Dynamics Class diagrams capture static properties of the system Class diagrams capture static properties of the system responsibilities and (maybe) state for a class responsibilities and (maybe) state for a class associations among classes associations among classes In some/most systems, describing the dynamics is equally important In some/most systems, describing the dynamics is equally important flow of control (what statement gets executed next) flow of control (what statement gets executed next) interactions (what messages get passed around) interactions (what messages get passed around) state transitions (what states is the system in, and what actions cause it to go into the next state) state transitions (what states is the system in, and what actions cause it to go into the next state) Flow charts are the traditional method of describing non-object-oriented programs; object-oriented systems are often better characterized by describing interactions among objects Flow charts are the traditional method of describing non-object-oriented programs; object-oriented systems are often better characterized by describing interactions among objects

3 CS540 Software Design 3Lecture 18 What are Interaction Diagrams? Interaction diagrams describe how groups of objects collaborate Interaction diagrams describe how groups of objects collaborate Typically an interaction diagram captures the behavior of a single use case Typically an interaction diagram captures the behavior of a single use case shows a number of example objects, and the messages passed between them to realize the use case shows a number of example objects, and the messages passed between them to realize the use case There are two types of Interaction diagrams: There are two types of Interaction diagrams: Sequence diagrams Sequence diagrams Collaboration diagrams Collaboration diagrams

4 CS540 Software Design 4Lecture 18 Sequence Diagrams One sequence line per object called object lifeline One sequence line per object called object lifeline Lines between objects represent method calls and returns Lines between objects represent method calls and returns Main components of a sequence diagram Main components of a sequence diagram describing a single scenario describing a single scenario representing "typical" objects representing "typical" objects object lifelines object lifelines message passing message passing conditional conditional iterative iterative returns returns The charm The charm works well in a scenario-driven design environment works well in a scenario-driven design environment better characterization of object-oriented systems better characterization of object-oriented systems simple and visually suggestive simple and visually suggestive

5 CS540 Software Design 5Lecture 18 Step 1. Start with the Use Case Extended scenario for making a reservation (Air Gourmet Case Study) Extended scenario for making a reservation (Air Gourmet Case Study)

6 CS540 Software Design 6Lecture 18 Step 2. Draw Sequence Diagram Sequence diagram for making a reservation Sequence diagram for making a reservation

7 CS540 Software Design 7Lecture 18 Collaboration Diagrams In sequence diagrams, time is implicitly represented as going "down the page" In sequence diagrams, time is implicitly represented as going "down the page" object lifelines object lifelines message sequence top to bottom message sequence top to bottom In collaboration diagrams, the collaboration (message passing sequence) shows the passing of time In collaboration diagrams, the collaboration (message passing sequence) shows the passing of time no explicit visual representation of passing time no explicit visual representation of passing time

8 CS540 Software Design 8Lecture 18 Collaboration Diagram for Air Gourmet Case Study Collaboration diagram for sending and returning a postcard Collaboration diagram for sending and returning a postcard

9 CS540 Software Design 9Lecture 18 Collaboration Diagrams (summary) Individual objects are icons in the diagram Individual objects are icons in the diagram identified by class name, and possibly an instance name identified by class name, and possibly an instance name Flow of time is tracked by message numbers Flow of time is tracked by message numbers phases of activity are harder to keep track of phases of activity are harder to keep track of Same iteration and conditional constructs Same iteration and conditional constructs More emphasis on the objects and their names More emphasis on the objects and their names

10 CS540 Software Design 10Lecture 18 State Diagrams Example of an extremely common and general form of system modeling (FSMs, decision processes, control theory, Petri Nets, state charts, etc. etc.) Example of an extremely common and general form of system modeling (FSMs, decision processes, control theory, Petri Nets, state charts, etc. etc.) system can be in some set of states s 1, s 2,... system can be in some set of states s 1, s 2,... there is a designated start state there is a designated start state actions (activities, program steps) cause state changes actions (activities, program steps) cause state changes execution continues until system enters a designated termination state execution continues until system enters a designated termination state

11 CS540 Software Design 11Lecture 18 UML State Diagrams States are rectangles/nodes States are rectangles/nodes Actions are coarse-grained abstract behaviors Actions are coarse-grained abstract behaviors execution happens within a state until there is a state change execution happens within a state until there is a state change Arcs between states are "guard conditions" (condition that must be true for a transition to the destination state) Arcs between states are "guard conditions" (condition that must be true for a transition to the destination state)

12 CS540 Software Design 12Lecture 18 State Diagram for Air Gourmet Case Study

13 CS540 Software Design 13Lecture 18 Activity Diagrams In the state diagram graph In the state diagram graph nodes represent system states nodes represent system states activities take place implicitly inside the states activities take place implicitly inside the states arcs are state transition conditions arcs are state transition conditions In activity diagram In activity diagram nodes represent activity (a linear sequence of actions) nodes represent activity (a linear sequence of actions) arcs represent control flow (conditional or parallel execution) arcs represent control flow (conditional or parallel execution)

14 CS540 Software Design 14Lecture 18 Activity Diagram for Air Gourmet Case Study

15 CS540 Software Design 15Lecture 18 Summary Interaction diagrams represent interaction among classes/objects Interaction diagrams represent interaction among classes/objects sequence diagrams are simplest, but time is linear and hard to represent complex interactions over time sequence diagrams are simplest, but time is linear and hard to represent complex interactions over time collaboration diagrams represent time via message sequence numbers; easier to show a complex sequence, harder to follow the flow collaboration diagrams represent time via message sequence numbers; easier to show a complex sequence, harder to follow the flow State diagrams show system states and state-change transitions Activity diagrams show parallel and conditional execution - very close to the old flowchart system


Download ppt "Lecture 18: Object-Oriented Design – Interaction and State Diagrams Anita S. Malik Adapted from Schach (2004) Chapter 12."

Similar presentations


Ads by Google