Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software engineering Methods 234321 Software Engineering Methods State Diagrams Zvi Avidor Written By With additions by Zvika Gutterman and Adam Carmi.

Similar presentations


Presentation on theme: "Software engineering Methods 234321 Software Engineering Methods State Diagrams Zvi Avidor Written By With additions by Zvika Gutterman and Adam Carmi."— Presentation transcript:

1 Software engineering Methods 234321 Software Engineering Methods State Diagrams Zvi Avidor Written By With additions by Zvika Gutterman and Adam Carmi

2 Software engineering Methods 234321 State Diagram A Type of a finite state machine. Best for modeling one class whose behavior depends on its state –Models the states of an object and how it moves from state to state for its entire lifetime –Describes the behavior of an object across several use cases A class should have its own state diagram if it has interesting dynamic behavior. –Controllers –Devices (e.g. modem – dialing, sending, receiving) –Objects that change state or role (e.g. a Book may be borrowed, overdue or in Library)

3 Software engineering Methods 234321 Example Starting PointStates End Point(s) Flying eating born dead Found food suffocated Out of fuel Idle State Transition Event

4 Software engineering Methods 234321 Events “An event is something that happens and that may cause some action” Stimuli that affects an object –Primary means of communication between objects Drive objects from one state to another Corresponds to: –Operations –Modification of attribute values –Passage of a designated period of time The source events is not specified

5 Software engineering Methods 234321 States Name State variables Activities & Actions All compartments are optional

6 Software engineering Methods 234321 State Variables The composite values of all attributes and links held by an object represent the object’s identity Ignore attributes that do not affect the objects behavior Lump together sets of values that have the same response to events Temporary attributes (that trigger events) may also be represented

7 Software engineering Methods 234321 Activities & Actions Activity –Takes time –Associated only with states –May be interrupted by some event –Can often be modeled as a nested state diagram –Examples: Downloading a file Printing Stop watch

8 Software engineering Methods 234321 Activities & Actions (cont.) Action –Have short duration –Associated with states and transitions –Atomic –Examples: audible beep display a menu set a flag sending a message (firing an event)

9 Software engineering Methods 234321 Activities & Actions (cont.) Actions can be spawned on entry and exit to states –entry/ entry-action(s) –exit/ exit-action(s) Activities may be indicated –do/ activity(ies) Internal events may be indicated (instead of self directed transitions) –internal-event/ action(s)

10 Software engineering Methods 234321 Activities & Actions (cont.) Example: Login registered = true entry/type “login” exit/login(user name, password) do/get user name do/get password help/display help Actions/Activities should be specified as operation signatures whenever possible Internal event

11 Software engineering Methods 234321 Transitions A transition is a relationship between a source state and a target state indicating that an object having the source state will change its state to the target state, when a specified set of events occur and/or a set of conditions are satisfied A self transition is a transition whose source and target states are the same Actions may be attached to transitions Transitions from the same state must be mutually exclusive. Otherwise, object’s state is undefined

12 Software engineering Methods 234321 Transitions (cont.) Represented as a directed edge between two states Transition (general) syntax: –event (attributes) [ condition(s) ] / action(s) ^ send- clause –All components are optional Transition semantics: –IF the event occurs AND all specified conditions are true THEN spawn the specified actions and change object state to the target state –If the triggering event is not specified, the transition will be attempted when all the state activities complete

13 Software engineering Methods 234321 Transitions (cont.) –A send-clause is used to send a message (event) to other objects (or to the same object) Syntax: destination-expression ‘.’ destination-event- name (arguments) Example: awakeasleep fall asleep() ^ myFriends.tell("be quiet")

14 Software engineering Methods 234321 Examples Idle - Puppy do/ Bark() Puppy Eating entry/ findNipple(myMom) do/ suck(nipple) [isHungry] Sitting Puppy do/ LickRandomBodyPart sit(aPlane) Boot do/ run bios Starting OS do/ load OS Start applications do/ load applications It would be better to add the guard condition [!isHungry]

15 Software engineering Methods 234321 Sub-states A sub-state is a state that is contained in another state (a composite state) Sub-states may be nested to any level Example: Eating ChewingBiteSwallowing Composite state Sub state

16 Software engineering Methods 234321 Transitions to/from composite states If the transition is to a composite state the nested state diagram must have an initial state If the transition is to a sub-state the sub-state entry action is executed after all entry actions of the composite state are executed If the transition is from a sub-state the sub-state exit action is executed followed by any exit action of the composite state A transition from the composite state may occur from any of the sub-states and takes precedence over any of the transitions of the current sub-state

17 Software engineering Methods 234321 Sub-states (cont.) ‘or’ sub-state –Sub-states can occur only one at the time ForwardBackward Driving

18 Software engineering Methods 234321 Sub-states (cont.) ‘and’ sub-states –Some of the sub-states can exist simultaneously ForwardBackward Driving Low speedHigh speed

19 Software engineering Methods 234321 History indicator Used to memorize internal states –usually used in cases we want to return to an interrupted state Cook Prepare ingredients Prepare food Answer Phone Prepare kitchen H


Download ppt "Software engineering Methods 234321 Software Engineering Methods State Diagrams Zvi Avidor Written By With additions by Zvika Gutterman and Adam Carmi."

Similar presentations


Ads by Google