27
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26

SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Embed Size (px)

Citation preview

Page 1: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

SOFTWARE DESIGN AND ARCHITECTURE

LECTURE 26

Page 2: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Review

• UML behavioral Diagrams– Sequence diagram

Page 3: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Outline

• UML Behavioral Diagrams– State Machine Diagram• Elements of a State Machine Diagram• Creating a State Machine Diagram

Page 4: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

State Machine Diagram

• Some of the classes in the class diagrams are quite dynamic in that they pass through a variety of states over the course of their existence.– For example, a vehicle can change over time from

being “new” to “pre-owned,” on the basis of its status with the dealership.

Page 5: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

State Machine Diagram

A behavioral state machine diagram is a dynamic model that shows the different states that a single class passes through during its life in

response to events, along with its responses and actions.

Page 6: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

State Machine Diagram

• What objects are best used with state diagrams?– large, complex objects with a long lifespan– domain ("model") objects– not useful to do state diagrams for every class in

the system!

Page 7: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

State Machine Diagram

• Typically, behavioral state machine diagrams are not used for all classes, but just to further define complex classes to help simplify the design of algorithms for their methods.

• The behavioral state machine diagram shows the different states of the class and what events cause the class to change from one state to another.

Page 8: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

State Machine Diagram

• In comparison to the sequence diagrams, behavioral state machine diagrams 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.

Page 9: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Elements of a Behavioral State Machine Diagram

• State– A state is a set of values that describes an object

at a specific point in time, – and it represents a point in an object’s life in

which it • satisfies some condition, • performs some action, or • waits for something to happen.

Page 10: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Elements of a Behavioral State Machine 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.

Page 11: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Elements of a Behavioral State Machine Diagram

• States:– An initial state is shown by a small, solid, filled-in

circle, and – An object’s final state is shown as a circle surrounding

a small, solid, filled-in circle.

• 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.

Page 12: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Elements of a Behavioral State Machine Diagram

• Event – 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 object’s state.

– It can be a designated condition becoming true, – the receipt of the call for a method by an object, – or the passage of a designated period.

Page 13: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Elements of a Behavioral State Machine Diagram

• A transition – is a relationship that represents the movement of

an object from one state to another state.

• A guard condition – is a Boolean expression that includes attribute

values, which allows a transition only if the condition is true.

Page 14: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Elements of a Behavioral State Machine Diagram

• internal activity: – actions that the

central object takes on itself

– sometimes drawn as self-transitions(events that stay in same state)

• entry/exit activities– reasons to start/stop being in that state

Page 15: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram
Page 16: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram
Page 17: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Super/sub-states

• When one state is complex, you can include sub-states in it.– drawn as nested rounded rectangles within the larger state

• Caution: Don't over-use this feature.– easy to confuse separate states for sub-states within one

state

Page 18: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Creating a Behavioral State Machine Diagram

• Behavioral state machine 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.

Page 19: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Creating a Behavioral State Machine Diagram

• You should examine your class diagram to identify which classes will need to undergo a complex series of state changes and draw a diagram for each of them.

Page 20: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Creating a Behavioral State Machine Diagram

• Identify the States – The first step is to identify the various states that a

selected tune will have over its lifetime. – This information is gleaned from reading the use

case reports, talking with users, and relying on the requirements-gathering techniques

Page 21: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Creating a Behavioral State Machine Diagram

• Identify the Transitions – The next step is to identify the sequence of states

that a selected object will pass through during its lifetime and

– then determine exactly what causes each state to occur.

– Place state figures on the diagram to represent the states and label the transitions to describe the events that are taking place to cause state changes.

Page 22: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Example – Customer Order

1. The customer adds items into the shopping cart.2. The customer checks out and submits the purchase

once he or she is finished.3. The purchase is pending while payment is

authorized.4. The payment is approved.5. The purchase is pending for final customer approval.6. The customer confirms the purchase.7. The download is released.

Page 23: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Example – Customer Order

Page 24: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Example - ATM software states

Page 25: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Concurrent Substates

© Oscar Nierstrasz

Page 26: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Branching and Merging

• Entering concurrent states:– Entering a state with concurrent substates means

that each of the substates is entered concurrently (one logical thread per substate).

• Leaving concurrent states:– A labelled transition out of any of the substates

terminates all of the substates.– An unlabelled transition out of the overall state waits

for all substates to terminate.

Page 27: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram

Summary

• UML Behavioral Diagrams– State Machine Diagram• Elements of a State Machine Diagram• Creating a State Machine Diagram