state modeling

13
1 State Modeling Events States Transitions and Conditions State Diagrams State Diagram Behavior Practical Tips

Upload: gettogether

Post on 18-Aug-2015

3 views

Category:

Documents


0 download

DESCRIPTION

oomd state modeling

TRANSCRIPT

1State ModelingEventsStatesTransitions and ConditionsState DiagramsState Diagram BehaviorPractical Tips2EventsEvent: occurrence at a point in time, such as user depresses left utton! Events often correspond to vers in the past tense or the onset of some condition, and represent points in time! "ne event ma# logicall# precede or follo$ another, or the t$o events ma# e unrelated! T$o events that are causall# unrelated are said to e concurrent% the# have no effect on each other! &f the communication dela# et$een t$o locations e'ceeds the difference in event times, then the events must e concurrent ecause the# can(t influence each other! &n modeling a s#stem $e do not tr# to estalish an ordering et$een concurrent events ecause the# can occur in an# order! Events include error conditions as $ell as normal occurrences! )or e'ample, motor *ammed, transactions aorted and timeout are t#pical error events! +Signal Event, signal is an explicit one-way transmission of information from one o*ect to another! &t is different from a suroutine call that returns a value! ,n o*ect sending a signal to another o*ect ma# e'pect a repl#, ut the repl# is a separate signal under the control of the second o*ect, $hich ma# or ma# not choose to send it! Signal event is the event of sending or receiving a signal! The difference et$een signal and signal event, a signal is a message et$een o*ects $hilea signal event is an occurrence in time!Ever# signal transmission is a uni-ue occurrence, ut the# are grouped into signal classes and give each signal class a name to indicate common structure and ehavior! The .M/ notation is the 0e#$ord signal in 1234 aove the signal class name in the top section of a o'! The second section lists the signal attriutes! 5signalFlightDepartureAirlineflightNumberCitydatesignalMouseButtonPushedButtonlocationsignalStringEnteredtextsignalReceiverLiftedsignalDigitDialeddigit Signal classes and attriutes6Change Event, change event is an event that is cause # the satisfaction of a oolean e'pression! The intent of a change event is that the e'pression is continuall# tested! 7henever the e'pression changes from false to true, the events happens! The UML notation for a change event is the 0e#$ord $hen follo$ed # a parenthesi8ed oolean e'pression! The ne't figure sho$s several e'amples of change events! $hen 1room temperature 9 heating set point4$hen 1room temperature : cooling set point4$hen 1atter# po$er 9 lo$er limit4$hen 1tire pressure 9 minimum pressure4 ;Time Event, time event is an event cause # the occurrence of an asolute time or the elapse of a time interval! The .M/ notation for an asolute time is the 0e#$ord $hen follo$ed # a parenthesi8ed e'pression involving time! The notation for a time interval is the 0e#$ord after follo$ed # a parenthesi8ed e'pression that evaluates to a time duration! The ne't figure sho$s an e'ample of time events! $hen 1date>>4 after 11> seconds4 ?StatesState: astraction of values@lin0s of an o*ect, and represent intervals of timeSets of values and lin0s are grouped together into a state according to the gross ehavior of o*ects! States often correspond to vers $ith a suffi' of AingB or the duration of some conditionThe ne't figure sho$s the .M/ notation for a stateC a rounded o' containing an optional state name! Solvent &nsolvent 7aiting Dialing Po$eredDState 1cont!4&n defining states, $e ignore attriutes that do not affect the ehavior of the o*ect,The purpose of modeling is to focus on -ualities that are relevant to the solution of an application prolem and astract a$a# those that are irrelevant! The three .M/ models 1class, state, and interaction4 presents different vie$s of a s#stem for $hich the particular choice of attriutes and values are not e-uall# important!The o*ects in a class have a finite numer of possile statesCone or possil# some larger numer! Each o*ect can onl# e in one state at a time!EState 1cont!4 Events vs! stateThere is a certain s#mmetr# et$een events and states as the ne't figure illustrates! Events represent points in time% states represent intervals of time! , state corresponds to the interval et$een t$o events received # an o*ect! The state of an o*ect depends on past events, $hich in most cases are eventuall# hidden # suse-uent events! )or e'ample, events that happened efore the phone is hung up do not affect future ehavior% the &dle state forgets events received prior to the receipt of the hang up signal! timepo$er turned onpo$er turned off po$er turned onPo$ered Fotpo$ered1>Garious Characteri8ations ofa stateState: ,larmHingingDescription: alarm on $atch is ringing to indicate target timeEvent sequence that produces the state:set,larm 1targetTime4 an# se-uence not including clear,larm7hen 1currentTime < targetTime4Condition that characterizes the state: alarm< on, alarm set to targetTime, targetTimeI currentTime I targetTime J 2> seconds, and no uttons has een pushed since targetTime Events accepted in the state: event response next state $hen 1currentTime < targetTime J 2>4reset,larm normaluttonPushed 1an# utton4 reset,larm normal11Transitions and Conditions, transitions is an instantaneous change from one state to another! The transition is said to fire upon the change from the source state to the target state! The origin and target of a transition usuall# are different states, ut ma# e the same! , transition fires $hen its event occursThe choice of ne't state depends on oth the original state and the event received!,n o*ect ma# cause multiple o*ects to transition% from a conceptual point of vie$ such transitions occur concurrentl#!, guard condition is a oolean e'pression that must e true in order for a transition to occur!, guard transition fires $hen its event occurs, ut onl# if the guard condition is true!)or e'ample, $hen #ou go out in the morning 1event4, if the temperature is elo$ free8ing 1condition4, then put on #our gloves 1ne't state4, guard condition is chec0ed onl# once, at the time the event occurs, and the transition fires if the condition is true!12Kuarded transitionsThe .M/ notation for a transition is a line from the origin state to the target state,n arro$head points to the target state! The line ma# consist of several line segments! ,n event ma# lael the transition and e follo$ed # an optional guard condition in s-uare rac0ets! 1+North /southMay go straightNorth/ southMay turn letEast/ !estMay turn letEast/ !estMay go straighttimeout[ cars in N/S left lanes]timeouttimeout [care in E/ left lanes]timeout!imeout [no cars in E/left lanes]!imeout [no cars in N /S left lanes]