Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10 Object States and The Statechart Diagram

Similar presentations


Presentation on theme: "Chapter 10 Object States and The Statechart Diagram"— Presentation transcript:

1 Chapter 10 Object States and The Statechart Diagram

2 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Events and States. Transitions and Actions. The Statechart Diagram. Object Lifecycles on the Statechart Diagram. The State Transition Table (STT).

3 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Events and States. Transitions and Actions. The Statechart Diagram. Object Lifecycles on the Statechart Diagram. The State Transition Table (STT).

4 In the real world (See Chapter 5):
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. In the real world (See Chapter 5): A Purchase Order begins life as a request document, gets authorized at various levels, goes out to a vendor, is fulfilled by receiving the goods, and finally is archived for future reference.

5 States in the real world:
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. States in the real world: Many objects in the real world go through a predictable cycle From their creation, Through their useful life, From stage to stage Until they die or are somehow disposed of (Archived or deleted or whatever.)

6 Object Behaviors State Changes Business Events cause which cause
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. Business Events cause State Changes which cause Object Behaviors to be executed.

7 As the act or experience of changing from one state to another.
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. We define a State Transition As the act or experience of changing from one state to another.

8 Lifecycle. As we follow an object from state to state,
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. As we follow an object from state to state, it traces what we can call its Lifecycle.

9 is to discover Operations for the classes we found in the
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. So our goal in studying Object Lifecycles is to discover Operations (i.e., Behaviors) for the classes we found in the earlier steps.

10 Here’s an example using a
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. Here’s an example using a library book . . .

11 Our typical library book Begins its day on the shelf. . .
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. Our typical library book Begins its day on the shelf. . . 1. Shelved 1. Shelved

12 And when a Subscriber comes along This is a Business Event . . .
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. 1. Shelved 1. Shelved And when a Subscriber comes along and borrows the Book This is a Business Event . . .

13 “Signed Out.” The state of the Book changes to
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. The state of the Book changes to “Signed Out.” 1. Shelved 1. Shelved 2. Signed Out

14 When the Subscriber brings it back. . .
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. When the Subscriber brings it back. . . The state of the Book changes to “Checked In.” 1. Shelved 1. Shelved 3. Checked In 2. Signed Out

15 And when the Librarian puts it back on the shelf,
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. And when the Librarian puts it back on the shelf, The state of the Book changes back to“Shelved.” 1. Shelved 1. Shelved 3. Checked In 2. Signed Out

16 does not repeat, A loop like this is an Operational Lifecycle,
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. A loop like this is an Operational Lifecycle, concerned with the regular operation of the users’ business. Many objects have a life that does not repeat, But goes stage to stage from “birth” to “death” (i.e., delete, archive, or whatever.) That kind is called a Lifetime

17 State. Definition: State: At any moment, an object exists
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. Definition: State: At any moment, an object exists in a certain condition or manner of being, and this we say is its State.

18 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Transitions and Actions. The Statechart Diagram. Object Lifecycles on the Statechart Diagram. The State Transition Table (STT). Events and States.

19 A noteworthy happening.
Chapter 10: Object States and the Statechart Diagram Events and States. Event: A noteworthy happening. (Webster) We say that: An Event is received by an object, Which really means the event happens to that object.

20 And once the event has happened to it, The object is in a new state.
Chapter 10: Object States and the Statechart Diagram Events and States. And once the event has happened to it, The object is in a new state.

21 we must change the value of at least
Chapter 10: Object States and the Statechart Diagram Events and States. Generally, To record a business event, we must change the value of at least one attribute. Since the attribute values can be said to represent the object’s state, this causes a State Transition.

22 “Status” attribute, and
Chapter 10: Object States and the Statechart Diagram Events and States. In fact, many classes have a “Status” attribute, and the domain of its permissible values Gives the set of possible states for that class.

23 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Events and States. The Statechart Diagram. Object Lifecycles on the Statechart Diagram. The State Transition Table (STT). Transitions and Actions.

24 of changing from one state to another.
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. Definition: State Transition: The act or experience of changing from one state to another.

25 Chapter 10: Object States and the Statechart Diagram 10. 3
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. We define an Object Lifecycle As consisting of the various states that an object may transition through, The set of permissible transitions, And the sequencing of those states and transitions, as it progresses from its initial creation to its eventual disposal.

26 Action: An Action is a behavior associated with a state or transition,
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. Action: An Action is a behavior associated with a state or transition, Executed each time the object enters or leaves that state (or executes that transition)

27 “Signed Out.” When the state of the Book changes to
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. When the state of the Book changes to “Signed Out.” 1. Shelved 1. Shelved There are some things that must happen, to keep track of all the loans 2. Signed Out

28 entry / Loan.L1: Request Link to Subscriber
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. When the state of the Book changes to “Signed Out.” 1. Shelved 1. Shelved When it is loaned out, the Book must in some way be attached to the borrower 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateTimeIn() 2. Signed Out entry / Loan.L1: Request Link to Subscriber

29 entry / Loan.L1: Request Link to Subscriber
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. When the state of the Book changes to “Signed Out.” 1. Shelved And when it leaves the state of “Signed Out,” it must update the Date and Time In. 1. Shelved 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateTimeIn() 2. Signed Out exit / UpdateTimeIn()

30 Action: stays within this state.
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. Action: Each Action is attached to either the entry into the state, or the exit from the state. Sometimes an Action is attached to a transition and executes during the transition. Sometimes an Action is attached to an event, and executes while the object stays within this state. We’ll look at these ones later . . .

31 within the box for the class
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. On the Statechart Diagram, Actions may be spelled out within the box for the class (Or documented separately if too many) At Analysis time, we just want to find Names for the actions, to be expanded and spelled out in the Design phase.

32 Actions can do anything:
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. Actions can do anything: Update attributes, Create instances, Send messages to other classes, i.e., generate an event to be received by another class and cause a transition in that other class (or even create an instance there.)

33 Object Behaviors State Changes Remember: Business Events cause
Chapter 10: Object States and the Statechart Diagram Lifetimes and Lifecycles. Remember: Business Events cause State Changes which cause Object Behaviors (i.e., Actions) to be executed.

34 Object Behaviors The goal of the Statechart Diagram
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. The goal of the Statechart Diagram Is to find the Actions So from them we may identify And later spec out in detail, the Object Behaviors and Methods.

35 And the tool for studying and documenting object lifecycles is the
Chapter 10: Object States and the Statechart Diagram Transitions and Actions. And the tool for studying and documenting object lifecycles is the Statechart Diagram . . .

36 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Events and States. Transitions and Actions. Object Lifecycles on the Statechart Diagram. The State Transition Table (STT). The Statechart Diagram.

37 Chapter 10: Object States and the Statechart Diagram 10. 4
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram For a Library Book. 1. Shelved entry / Update Date & time Shelved Event B4: «create» Book is Purchased Event B1: Subscriber Requests Loan / Update Date & Time Out Event B3: Librarian Shelves Book 3. Checked In entry / Loan.L2: Archive Loan 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() Event B2: Subscriber Returns Book

38 a large black dot Events are shown with arrows.
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Notation Events are shown with arrows. The event that causes the instance to be created is shown as coming from a large black dot and is “stereotyped” «create» (e.g., Event B4) Event B2: Subscriber Returns Book 1. Shelved 2. Signed Out 3. Checked In Update Date/time Shelved Event B1: Subscriber Requests Loan Update Date/time Out Generate Event SO1: Request Link to Subscriber Update Date/Time In Generate Event SO2: Archive Sign-Out Event B3: Librarian Shelves Book Event B4: Book is Purchased Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

39 State numbers are unique within that Statechart Diagram
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Notation State numbers are unique within that Statechart Diagram e.g., “2: Signed Out” Event numbers are unique within the project Event numbers have a prefix telling what class they belong with, e.g.: “B3: Librarian Shelves Book” belongs in the Book class. “L1: Create Loan Instance” is in the Loan class. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

40 Now let’s follow the Book through its daily routine. . .
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Notation Now let’s follow the Book through its daily routine. . . Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

41 Update Date & Time Shelved
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram The Book is purchased (Event B4) and enters its initial state (State 1: Shelved) As it enters State 1, it executes the Entry Action for that state, Update Date & Time Shelved Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

42 (Event B1) A subscriber (customer) borrows the Book
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram A subscriber (customer) borrows the Book (Event B1) This causes it to transition to State 2: Signed Out As the Book is in transition it executes the Action for that transition: Update Date & Time Out Then, as it enters State 2, it executes the Entry Action for that state, Request Link to Subscriber Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

43 Action: An Action is a behavior Associated with a state or transition,
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram. Action: An Action is a behavior Associated with a state or transition, Executed each time The object enters or leaves that state or executes that transition. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

44 In other words, An Action is a set of things that the object must do
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram In other words, An Action is a set of things that the object must do when it transitions into or out of a state or during a transition. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

45  Request Link to Subscriber Note that in this case, the Book object
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Note that in this case, the Book object updates the Date and Time Out Request Link to Subscriber as it transitions from State 1 to State 2, And as it enters State 2, generates an Event L1: Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

46 The Event SO1 is then received by the Statechart
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram The Event SO1 is then received by the Statechart Diagram for the Loan class. This causes a Loan instance to be created in its initial state, State 1: Current. 1. Current Event L1: Request Link to Subscriber «create» Update Date/time Out Generate Event SO1: Request Link to subscriber Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

47  Next, Event B2 happens, The Subscriber returns the Book
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Next, Event B2 happens, The Subscriber returns the Book And the Book transitions to State 3. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan 3. Checked In entry / Loan.L2: Archive Loan

48 it executes the Exit Action, UpdateDateAndTimeIn()
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram As the Book leaves State 2: Signed out it executes the Exit Action, UpdateDateAndTimeIn() Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan exit / UpdateDateAndTimeIn()

49 Generate Event L2: Archive Loan
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram As the Book enters State 3: Checked In It executes the Entry Action, Generate Event L2: Archive Loan. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan Generate Event L2: Archive Loan

50 The Loan instance Transitions to State 2: Archived, and
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram When Event L2 is received by the Statechart Diagram for the Loan class, The Loan instance Transitions to State 2: Archived, and executes the Action for that transition: UpdateAverageDurationOfLoansAllBooks() Event L1: Request Link to Subscriber «create» Event L2: Loan is Archived / UpdateAverageDurationOfLoan sAllBooks() 1. Current Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan 2. Archived entry / Update Archive Status

51 Chapter 10: Object States and the Statechart Diagram 10. 4
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Then, as the Loan object enters State 2: Archived, It executes the Entry Action Update Archive Status entry / Update Archive Status Event L1: Request Link to Subscriber «create» 1. Current Event L2: Loan is Archived / UpdateAverageDurationOfLoansAllBooks() Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan 2. Archived

52 The last two events in the cycle are unrelated:
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram The last two events in the cycle are unrelated: Event B3 puts the Book back in State 1: Shelved. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

53 and deletes all the archived Sign-Outs, after a suitable period.
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Finally, Timer Event L3 happens After(90 Days) and deletes all the archived Sign-Outs, after a suitable period. Event L1: Request Link to Subscriber «create» 1. Current Event L2: Loan is Archived / UpdateAverageDurationOfLoansAllBooks() Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan 2. Archived entry / Update Archive Status Event L3: After(90 days) / Delete Archived Loan

54 Note that in this example,
Chapter 10: Object States and the Statechart Diagram The Statechart Diagram Note that in this example, The Loan has a Lifetime, And the Book has a repeating Lifecycle . . . Event L1: Request Link to Subscriber «create» 1. Current Event L2: Loan is Archived / UpdateAverageDurationOfLoansAllBooks() Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan 2. Archived entry / Update Archive Status Event L3: After(90 days) / Delete Archived Loan

55 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Events and States. Transitions and Actions. The Statechart Diagram. The State Transition Table (STT). Object Lifecycles on the Statechart Diagram.

56 An Object Lifecycle consists of the various states
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram. Definition: An Object Lifecycle consists of the various states that an object may transition through, The set of permissible transitions, and the sequencing of those states and transitions.

57 Actions for each state, event and transition,
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram. The Lifecycle also includes Actions for each state, event and transition, Actions that are executed each time the object enters or leaves that state or executes the transition

58 “Interesting Lifecycle,”
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram But which classes need a Statechart Diagram? Pick the classes we figure will have an “Interesting Lifecycle,” Also include those with a lifetime linked with the “interesting” ones.

59 By “Interesting” it means those with:
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram By “Interesting” it means those with: A repeating operational lifecycle (e.g., Library Book), A complex lifetime with branches and backtracks (e.g., Purchase Order), A long lifetime with many states, Anything we judge may be a fruitful source of Actions and operations.

60 Chapter 10: Object States and the Statechart Diagram 10. 5
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram Since all instances in a class have the same lifecycle, It follows that they all have the same Statechart Diagram. However, for executing its Statechart Diagram, Each separate instance proceeds at its own pace, As events arrive to step it through its lifecycle. We have a name for this. . .

61 A State Machine is the set of actual historical events
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram Definition: A State Machine is the set of actual historical events that took place during the execution of a Statechart Diagram by a particular specified object instance.

62 that will make up the rest of the path that this instance will take
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram Definition: State Machine It may also include the future events that will make up the rest of the path that this instance will take through the Statechart Diagram.

63 This is different from the Statechart Diagram itself
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram Definition: State Machine This is different from the Statechart Diagram itself which may be viewed as an abstraction of the State Machines of all the instances.

64 And now a Completeness Check
Chapter 10: Object States and the Statechart Diagram Object Lifecycles on the Statechart Diagram And now a Completeness Check That we must use on every Statechart Diagram. . .

65 Chapter 10: Object States and the Statechart Diagram
Lifetimes and Lifecycles. Events and States. Transitions and Actions. The Statechart Diagram. Object Lifecycles on the Statechart Diagram. The State Transition Table (STT).

66 Let’s take another quick look at the
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) Let’s take another quick look at the Library Book Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

67 every possible transition has been:
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) We need to check that every possible transition has been: Assigned a destination state, or Ruled as physically or legally impossible, or Designated as one that should be ignored. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

68 Here is a matrix tool that will
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) Here is a matrix tool that will help you do that, It’s called a State Transition Table . . . Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

69 ? State Transition Table 1 2 3 1 Events States Ignore
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) State Transition Table Events B1: Subscriber Requests Loan B2: Subscriber Returns Book B3: Librarian Shelves Book is Purchased B4: Book States 1 0. Null Impossible Impossible Impossible 1. Shelved 2 Impossible Impossible Impossible 2. Signed Out Ignore 3 Impossible Impossible ? 1 3. Checked In Impossible Impossible Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan But what about the blank in the bottom leftmost box? What happens if a loan is requested while the Book is in the Checked-In bin, waiting to go back on the shelf?

70 It would not make sense, our users tell us,
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) It would not make sense, our users tell us, to refuse to lend a book when it is available from the Checked-In bin! So our State Transition Table has highlighted a deficiency in the Statechart Diagram. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

71 So we add an arrow from State 3 to State 2
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) So we add an arrow from State 3 to State 2 Triggered by an Event B1: Loan Requested Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan Event B1: Subscriber Requests Loan / Update Date/Time Out

72  State Transition Table 1 2 3 2 1 And we put a ‘2’ as
Chapter 10: Object States and the Statechart Diagram The State Transition Table (STT) State Transition Table Events B1: Subscriber Requests Loan B2: Subscriber Returns Book B3: Librarian Shelves Book is Purchased B4: Book States 1 0. Null Impossible Impossible Impossible 1. Shelved 2 Impossible Impossible Impossible 2. Signed Out Ignore 3 Impossible Impossible 2 1 3. Checked In Impossible Impossible And we put a ‘2’ as the destination state in the bottom left box. Event B1: Subscriber Requests Loan / Update Date/Time Out Event B2: Subscriber Returns Book Event B3: Librarian Shelves Book Event B4: «create» Book is Purchased 2. Signed Out entry / Loan.L1: Request Link to Subscriber exit / UpdateDateAndTimeIn() 1. Shelved entry / Update Date & time Shelved 3. Checked In entry / Loan.L2: Archive Loan

73 End of Chapter 10


Download ppt "Chapter 10 Object States and The Statechart Diagram"

Similar presentations


Ads by Google