object states an object state is a condition or situation during the life of an object during which it: • satisfies some condition • or performs some activity • or waits for some event the current state of an object determines how it will behave the current state of an object is determined by: • current values of attributes • and current links with other objects University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 1 statechart diagram is a model of: • all the states and object can have • the events that cause transitions • all possible responses to all use cases Not all messages an object can receive will alter its state, in particular messages that do not cause changes to attributes or links (e.g. “get” and “query”) an object moves from one state to another by a transition which is either: • triggered by an event • or the state simply finishes (triggerless transition) University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 2 events events may trigger action by actor or object time end of designated time period after [time expression] change when a condition becomes true when [Boolean expression] signal receipt of an asynchronous communication signal call receipt of call for an operation (synchronous) from self or other object event-signature [guard-condition] / return-value:= action-expression University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 3 event-signature [guard-condition] / return-value:= action-expression event-signature guard-condition action expression operation (parameter-list) Boolean expression operation (paramter-list) A[B]/C if told to do A and B is true, then also do C, causing a state change if told to do A and B is false, then don’t do C and state does not change if no guard condition, then state always changes an example showing multiple actions. . . leftMouseDown(location) [validItemSelected] / menuChoice:= pickMenuItem(location); menuChoiceHighlight ( ) three more examples . . . • /assignManager ( ) ; assignStaff ( ) • authorization (authorizationCode) [contract signed] / setCampaignActive ( ) • paymentReceived ( payment) [paymentDue – payment <= zero] / University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 4 labels and notation state name menu visible event [guard condition] / action expression itemSelected ( ) / highlightItem ( ) entry / displayMenu ( ) exit / hideMenu ( ) do / playSoundClip ( ) event [guard condition] / action expression event-signature [guard-condition] / return-value:= action-expression University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 5 the event that creates the object on creation, the object moves immediately into the first named state initial state basic notation discountRate( ) pending when [discountStartDate <= currentDate] change events active transition when [discountFinishDate <= currentDate] lapsed after [1 year] elapsed-time event cannot leave final state once it has been entered University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 6 statechart for the class DiscountRate createDiscountdiscountRate( ) Rate ( ) pending when [discountStartDate <= currentDate] active <<entity>> when [discountFinishDate <= currentDate] discountRate rate discountStartDate discountFinishDate lapsed after [1 year] createDiscountRate ( ) assignLatestDiscountRate ( ) University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 7 hospital patient enters hospital entering checks in admitted [diagnosis = unhealthy] under observation [diagnosis = healthy] released [diagnosis = healthy] [> 2 weeks] University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 8 order is created pending customer withdraws order request online order customer submits order ordered order sent for credit authorization credit check [authorization = denied] denied [authorization = approved] placed University of Toronto at Scarborough order sent to customer © Kersti Wain-Bantin shipped received customer accepts shipment order is closed CSCC40 state charts 9 movie title <<PK>> movieCode : String movieTitle : String director : String inStock : Boolean available rent out (quantity) / subtract item (last item) video store – movie title not in stock return item (quantity / add quantity (no items) put on shelf (quantity) order item (quantity) replenish stock (quantity) in stock ordered order item (quantity) [insufficient stock] [no more reserved] reserved reserve (medium type) / update number reserved University of Toronto at Scarborough © Kersti Wain-Bantin not reserved CSCC40 state charts 10 online order pending new order back order stock not available stock available [ship date in future] future order stock available [ship date in future] stock available [ship date now] [canceled] cancelled [canceled] ready to ship ship [accepted] filled University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 11 alarm system after (10 seconds) / selfTest alarm () active initializing idle attention checking calling entry/callCenter ( ) clear command waiting attention entry / setAlarm exit / clearAlarm modeling the lifetime of an object University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 12 fax machine ringing receiving connected idle headerOK hangUp processing sendFax checkSumOK cleaning up transmitting error / printReport entry /pickUp exit / disconnect example of nested states within a composite state and triggerless transitions University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 13 concurrent substates name of state name of substate 1 A1 A2 A3 in this example, either transition T1 or T2 can cause the object to leave any of states A1, A2, A3 or B1, B2, B3 name of substate 2 B1 B2 and until either T1 or T2 occurs, the object remains in substate 1 and substate 2 B3 T1 University of Toronto at Scarborough T2 © Kersti Wain-Bantin CSCC40 state charts 14 when developing state charts . . . what are the major system events? what objects are affected by these events? (state charts are created) what alternate scenarios exist? (state charts are enhanced) are the state charts consistent with all use cases, collaboration and sequence diagrams? (state charts are corrected if necessary) University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 15 when checking statecharts . . . every event appears as an incoming message for the appropriate object in the right interaction (sequence or collaboration) diagram? corresponds to an operation on the appropriate class? every action appears as an operation in that object’s class? every outgoing message corresponds to an operation in another class? University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 16 example: Menu Visible state for a DropDownMenu object Event itemSelected() triggers the action highlightItem() Entry action causes the menu to be displayed Menu Visible itemSelected() / highlightItem() entry / displayMenu exit / hideMenu do / playSoundClip Exiting the state triggers hideMenu() While the object remains in the Menu Visible state, the activity causes a sound clip to be played University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 17 Synchronized Concurrent Threads. Synchronization bar Explicitly showing how an event triggering a transition to a state with nested concurrent states causes specific concurrent substates to be entered Shows that the composite state is not exited until both concurrent nested statecharts are exited University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 18
© Copyright 2026 Paperzz