Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML -Part 3. Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams.

Similar presentations


Presentation on theme: "UML -Part 3. Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams."— Presentation transcript:

1 UML -Part 3

2 Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams - emphasize time ordering – Communication Diagrams - emphasize structural ordering State Diagrams – State machine consisting of states, transitions, events and activities of an object Activity & Swimlane Diagrams – Emphasize and show flow of control among objects 2

3 Sequence Diagrams Describe the flow of messages, events, actions between objects Show concurrent processes and activations Show time sequences that are not easily depicted in other diagrams Typically used during analysis and design to document and understand the logical flow of your system 3

4 Sequence Diagram 4

5 5 Time Increasing --> All lines should be horizontal to indicate instantaneous actions. Additionally if ActivityA happens before ActivityB, ActivityA must be above activity A

6 Components 6 Objects: aStudent is a specific instance of the Student class Specific Instance of an Object Generic (unnamed) objects Generic (unnamed) objects of class type Seminar and Course

7 Components 7 lifeline execution

8 Components 8 Return value Method call

9 Components 9 c : Client : Transaction o : ODBCProxy create() setActions(a, b, c) setValues(a, 3, 4) setValues(b, c, 7) (committed) destroy() Synchronous message Asynchronous message create() destroy() Return message

10 Asynchronous Message Example 10 Synchronous message Asynchronous message Return message There are problems here… what are they?

11 Components: alt/else 11

12 Components: option 12

13 Components: loop 13

14 Rules of thumb Rarely use options,loops,alt/else – These constructs complicate a diagram and make them hard to read/interpret. – Frequently it is better to create multiple simple diagrams Create sequence diagrams for use cases when it helps clarify and visualize a complex flow Remember: the goal of UML is communication and understanding 14

15 Summary Sequence diagrams model object interactions with an emphasis on time ordering Method call lines – Must be horizontal! – Vertical height matters! “Lower equals Later” – Label the lines Lifeline – dotted vertical line Execution bar – bar around lifeline when code is running Arrows – Synchronous call (you’re waiting for a return value) – triangle arrow-head – Asynchronous call (not waiting for a return) – open arrow-head – Return call – dashed line 15

16 In class exercise Draw a sequence diagram for: – Getting on a flight. Start at home, check in at the counter, go through security, and end up at the gate. (If you have time during the exercise, get yourself to your seat.) You may get searched in security 16

17 In class exercise Draw a sequence diagram for: – Getting money from an ATM machine Treat each part of the ATM as a class – Money dispenser – Screen – Keypad – Bank computer – Etc… 17

18 State Diagrams Depicts object behavior across use cases State: collection of values of attributes State-behavior relationship – state is updated by some behavior carried out Notation – States: rounded rectangles – Arrows: state transitions – Labels on Arrows: event/action/use case 18

19 Example 1: Book in a Library System 19 New Available Reserved Borrowed start activate return borrow reserve release

20 What Are Statechart Diagrams? A statechart diagram shows a state machine, which specifies the sequences of states that an object can be in, the events and conditions that cause the object to reach those states, and the actions that take place when those states are reached. 20 Sample State 1 Sample State 2

21 Drawing States A state is represented as a rounded rectangle on a statechart diagram. As a comparison, note the subtle difference between a state versus an activity. 21 Sample State 1 Sample Activity

22 State and Attributes States may be distinguished by the values of certain attributes. The maximum number of students per course is 10. numStudents = 10 22 Closed Open

23 States and Links State may also be distinguished by the existence of certain links. Instances of class Professor can have two states – Teaching when a link to a course exists. – On sabbatical when no link exists. 23 Professor > Course > 0..* 11

24 Special States The initial state is the state entered when an object is created. – An initial state is mandatory. – Only one initial state is permitted. – The initial state is represented as a solid circle. A final state indicates the end of life for an object. – A final state is optional. – More than one final state may exist. – A final state is indicated by a bull’s eye. 24 Sample State 1 Sample State 2

25 What Are Events? An event is the specification of a significant occurrence that has a location in time and space. – An event is an occurrence of a stimulus that can trigger a state transition. – Example Adding a student to a course Creating a new course 25 State BState A Event

26 What Are Transitions? A transition is a change from an originating state to a successor state as a result of some stimulus. – The successor state could possibly be the originating state. A transition may take place in response to an event. Transitions can be labeled with events. 26 State BState A Event Transition

27 What Are Guard Conditions? A Boolean expression that is evaluated when the transition is triggered by the reception of the event trigger. If the expression evaluates to True, the transition is eligible to fire. If the expression evaluates to False, the transition does not fire. 27 State A Event[ thisAttribute >= 3 ] State B Guard Condition

28 What Are Actions? Executable atomic computations that result in a change in state of the model or the return of a value – Associated with a transition – Take an insignificant amount of time to complete – Non-interruptible 28 State A Event[ thisAttribute >= 3 ] / Action State B entry/ Action Actions

29 What Are Activities? Ongoing, non-atomic executions within a state machine – An operation that takes time to complete – Starts when the state is entered – Can run to completion or can be interrupted by an outgoing transition 29 State B entry/ Action do/ on Undefined/ State A Event[ thisAttribute >= 3 ] / Action Activities

30 Send Events One event may trigger the sending of another event. An activity can also send an event to another object. 30 State B entry/ Action do/ on Undefined/ ^Send Event Event[ thisAttribute >= 3 ] / Action ^Send Event State A

31 What Are Substates? Statechart diagrams can become very complex. Substates (nested states) can be used to simplify complex diagrams. A superstate is a state that encloses nested states called substates. Any number of levels of nesting are permitted. Nested states can lead to substantial reduction of graphical complexity, allowing us to model larger and more complex problems. 31

32 Statechart Diagram Without Substates 32 add student / numStudents = numStudents + 1 Unassigned Assigned Full Cancelled do: Send cancellation notices Committed do: Generate class roster closeRegistration [ has Professor assigned ] close / numStudents = 0 addProfessor closeRegistration remove student / numStudents = numStudents - 1 cancel removeProfessor [ numStudents = 10 ] close[ numStudents < 3 ] closeRegistration[ numStudents >= 3 ] close[ numStudents >= 3 ] add student / numStudents = numStudents + 1 cancel remove student / numStudents = numStudents - 1 close [ numStudents = 10 ] cancel

33 Statechart Diagram with Substates 33 superstate substate add student / numStudents = numStudents + 1 Open Unassigned Assigned H add a professor Closed Cancelled do: Send cancellation notices Full Committed do: Generate class roster closeRegistration close remove a professor close[ numStudents < 3 ] [ numStudents = 10 ] closeRegistration[ numStudents >= 3 ] close[ numStudents >= 3 ] closeRegistration [ has Professor assigned ] close / numStudents = 0 remove student / numStudents = numStudents - 1 cancel

34 When to Draw State Diagrams State diagrams are good at describing the behavior of an object across several use cases Use state diagrams only for those classes that exhibit interesting behavior, often the main classes of the system 34

35 State Diagrams Help Complete System Design State diagrams often reveal use cases overlooked in earlier analyses of the system State diagrams provide hints on which attributes are necessary for a given class 35

36 Activity Diagram Represents sequence of activities Depicts condition, iteration, and parallel activities When to use: – Analyzing use cases Alternate way of describing a use case Depicting use case sequences/workflow – Describing method behavior 36

37 Activity Diagram Notation Oval - activity Start and end buttons Links between ovals to depict sequence Diamond – conditional branch and merge Bar – fork and join (concurrent activities) 37

38 About Activity Diagrams Helps in understanding system behavior, but … it does not provide an object-oriented perspective! Suggestion: just use as a tool to clarify complex sequential/parallel relationships between behavioral components 38

39 CRC Cards Not really part of the UML – But helps in construction of Class Diagrams and Interaction Diagrams CRC: Class-Responsibility-Collaboration Role-playing: – Team members represent classes – Each member/class holds an index card 39

40 CRC Cards, continued Team goes through each use case and role-play object interaction Responsibilities (which end up being methods) are noted on the index card Use of an index card is deliberate – Responsibilities ought to be evenly distributed across the classes that interact – Overloaded classes become immediately apparent 40

41 CRC Cards and UML Diagrams Role-playing activity for each use case maps directly to interaction diagram construction Each card provide class details (methods) for the class diagram 41

42 Activity Diagram 42 Supplements the use-case by providing a diagrammatic representation of procedural flow Details: -Start is a single circle -End is a bulls-eye -Decisions are diamonds (guards must be on both branches of the diamond!) Questions: Do we always have a start? Do we always have an end?

43 Swimlane Diagrams 43 Allows the modeler to represent the flow of activities described by the use-case and at the same time indicate which actor (if there are multiple actors involved in a specific use- case) or analysis class has responsibility for the action described by an activity rectangle

44 Activity Diagram Example To show concurrent activity, activity diagrams allow branches and joins. You can also reference or include other activity diagrams 44 Fork/Branc h Join


Download ppt "UML -Part 3. Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams."

Similar presentations


Ads by Google