Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oct 200592.3913 R. McFadyen1 Statechart Diagrams Example: Suppose we have a class Copy, representing copies of books. We can consider two states: available,

Similar presentations


Presentation on theme: "Oct 200592.3913 R. McFadyen1 Statechart Diagrams Example: Suppose we have a class Copy, representing copies of books. We can consider two states: available,"— Presentation transcript:

1 Oct 200592.3913 R. McFadyen1 Statechart Diagrams Example: Suppose we have a class Copy, representing copies of books. We can consider two states: available, borrowed; and model how a single copy can move from one state to the other. Borrowed return borrow Available event transition another state Initial state

2 Oct 200592.3913 R. McFadyen2 Statechart Diagram A Statechart Diagram describes states for an object how/why an objects’ state changes A Statechart Diagram is a State Machine Possible states are related to an objects attributes, related classes, operations A State Diagram models an object’s decision about what it does when it receives a message

3 Oct 200592.3913 R. McFadyen3 States, Events, Transitions State - a condition or situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event. Event - a noteworthy occurrence An event can trigger a state transition Transition – a relationship between two states indicating that an object in the first state will perform certain actions and enter the second state when a specified event occurs and specified conditions are satisfied

4 Oct 200592.3913 R. McFadyen4 State Machine State Machine - a specification of the sequences of states that an object goes through in response to events during its life A State Machine is a graph of states and transitions that describes the response of an instance of a classifier to the receipt of events State Machines may be attached to classes, use cases,...

5 Oct 200592.3913 R. McFadyen5 State Diagram - General Form state1state2 event [guard] /action initial state We choose to represent events that suit us - enabling a diagram to represent the level of detail we need final state

6 Oct 200592.3913 R. McFadyen6 Employee Example WorkingOn Break Start break End break Suppose we have a class Employee, representing employees of our company Two states: working and on break

7 Oct 200592.3913 R. McFadyen7 Library Book Example Now consider a class Book. Suppose there may be several copies of the book. Here, we’ll model the states Borrowable, and Not borrowable, which are related to books (not copies). Not borrowableBorrowable returned borrowed[last copy] returned borrowed[not last copy]

8 Oct 200592.3913 R. McFadyen8 Library Book Example Not borrowableBorrowable returned borrowed[last copy] returned borrowed[not last copy] Note: when a Book receives the returned event, the next state depends only on the current state when a Book receives the borrowed event, the next state is determined by the guard

9 Oct 200592.3913 R. McFadyen9 Selling Seats Example availablefull Consider a situation where tickets are being sold for a voyage. Tickets can be sold as long as there are seats available. At some point, all seats could have been sold and the voyage is full. Eventually, sales are closed and no more seats can be sold. We’ll consider states full and available for a voyage. Seat sold [not last one] Seat sold [last one] Sales closed

10 Oct 200592.3913 R. McFadyen10 Process Sale Use Case We can construct a State Diagram showing states for this use case

11 Oct 200592.3913 R. McFadyen11 Waiting For Sale; Entering Items; Waiting For Payment are System states that arise in the Process Sale use case. Transitions are system events … the diagram clearly shows when events, such as makeNewSale, are legal.

12 Oct 200592.3913 R. McFadyen12 Including the Authorizing Payment state.

13 Oct 200592.3913 R. McFadyen13 Consider a banking environment where an Account is considered active when it is first created (i.e. opened). When a Customer performs a transaction (withdraws or deposits money), the balance in the Account is affected. If the Account balance becomes negative the Account is considered overdrawn. As well as withdraw or deposit money, a Customer might close his/her Account. Only active accounts can be closed. Closed accounts can be reopened. At some time in the future, after the Customer closed the account, the Bank might delete the Account (and it is gone forever). In the example, events, guards, transitions and actions are shown. Bank Account Example

14 Oct 200592.3913 R. McFadyen14 active Four States: active overdrawn closed deleted overdrawn deletedclosed Bank Account Example We’ll develop the example by considering each state, and the transitions that can occur when an account is in that state.

15 Oct 200592.3913 R. McFadyen15 active trx [pos] overdrawn trx [neg]/warn() closed close An account begins by being Active. Once in the Active state, the account can remain active, become overdrawn, or be closed. {trx stands for “transaction” which represents a deposit or withdrawal} Bank Account Example

16 Oct 200592.3913 R. McFadyen16 activeoverdrawn trx[pos] trx [neg]/warn() close /warn() From the Overdrawn state, an account can remain overdrawn, or move to the active state Bank Account Example [pos] is a guard that stands for “the account balance is positive” [neg] …

17 Oct 200592.3913 R. McFadyen17 deleted delete closed From the Closed state, an account can move to the Deleted state; it can also be made active again. Deleted is considered the final state for an account reopen active Bank Account Example

18 Oct 200592.3913 R. McFadyen18 active trx [pos] overdrawn trx [neg]/warn() deleted delete closed close trx [pos] trx [neg]/warn() close /warn() reopen All together: Bank Account Example


Download ppt "Oct 200592.3913 R. McFadyen1 Statechart Diagrams Example: Suppose we have a class Copy, representing copies of books. We can consider two states: available,"

Similar presentations


Ads by Google