Full Transcript

ACS2913 Software Requirements Analysis and Design Instructor: Victor Balogun OBJECT BEHAVIOR THE UNIVERSITY OF WINNIPEG - ACS 2913 1 Review Questions What is a state? 3 What is a State Machine? 3, 4 What is the difference between a state and a transition? 3 What i...

ACS2913 Software Requirements Analysis and Design Instructor: Victor Balogun OBJECT BEHAVIOR THE UNIVERSITY OF WINNIPEG - ACS 2913 1 Review Questions What is a state? 3 What is a State Machine? 3, 4 What is the difference between a state and a transition? 3 What is a State Machine diagram? 5 What are the uses or applications of State Machine diagram? 4 What are components of a State Machine diagram? 5 How many objects does a state machine diagram apply to? What is in the label for a transition? What does each part mean? 6 What is a concurrent state? 7 What is a concurrent path? 7 What is a composite state? 8 How are the synchronization bars used to represent concurrent paths? 10 What are the steps for creating a state machine diagram? 11 THE UNIVERSITY OF WINNIPEG - ACS 2913 2 Object Behavior – State Machine Diagram Each class has objects that may have status conditions or “states” Object behavior consists of the various states and the movement between these states State – a condition during an object’s life when it satisfies some criterion, performs an action, or waits for an event Transition – the movement of an object from one state to another A “State machine” is an abstract concept (a model) to identify objects behaving like a “Machine” that can be in one of many finite states. THE UNIVERSITY OF WINNIPEG - ACS 2913 3 State Machine Diagram A state machine is anything that can have different states. ◦In our case we will refer to the different states of an object ◦The states are the different combinations of information that an object can hold and not how they behave Applications of a State machine Diagram: ◦Depicting event-driven objects in a reactive system. ◦Illustrating use case scenarios in a business context. ◦Describing how an object moves through various states within its lifetime. ◦Showing the overall behavior of a state machine or the behavior of a related set of state machines. 4 THE UNIVERSITY OF WINNIPEG - ACS 2913 State Machine Diagram  State Machine Diagram – a diagram which shows the life of an object in states and transitions  Origin state – the original state of an object before it begins a transition  Destination state – the state to which an object moves after completing a transition  pseudostate – the starting point in a state machine diagram. Noted by a black circle.  action-expression – some activity that must be completed as part of a transition  guard-condition – a true/false test to see whether a transition can fire THE UNIVERSITY OF WINNIPEG - ACS 2913 5 State Machine for a Printer Syntax of transition statement ◦ transition-name (parameters, …) [guard-condition] / action- expression 6 THE UNIVERSITY OF WINNIPEG - ACS 2913 Concurrency in a State Machine Diagram Concurrent states – when an object is in one or more states at the same time Path – a sequential set of connected states and transitions Concurrent paths – when multiple paths are being followed concurrently, i.e. when one or more states in one path are parallel to states in another path THE UNIVERSITY OF WINNIPEG - ACS 2913 7 Composite States State containing other states and transitions Printer can be On and either Idle or Working THE UNIVERSITY OF WINNIPEG - ACS 2913 8 Concurrent Paths Multiple paths in composite state ◦ Printer On paths are independent THE UNIVERSITY OF WINNIPEG - ACS 2913 9 Printer with Concurrent Paths Concurrent paths often shown by synchronization bars (same as Activity Diagram) Multiple exits from a state is an “OR” condition. Multiple exits from a synchronization bar is an “AND” condition. THE UNIVERSITY OF WINNIPEG - ACS 2913 10 Creating a State Machine Diagram - Steps 1. Review the class diagram and select classes that might require 6. Look for additional transitions and state machine diagrams test both directions 7. Expand each transition with 2. For each class, make a list of status appropriate message event, guard conditions (states) you can identify condition, and action expression 3. Begin building diagram fragments 8. Review and test the state machine by identifying transitions that diagram for the class cause an object to leave the ◦ Make sure state are really state for the identified state object in the class 4. Sequence these states in the ◦ Follow the life cycle of an object coming into existence and being deleted correct order and aggregate ◦ Be sure the diagram covers all exception combinations into larger fragments condition 5. Review paths and look for ◦ Look again for concurrent paths and independent, concurrent paths composite states THE UNIVERSITY OF WINNIPEG - ACS 2913 11 RMO – Creating a State Machine Diagram Steps -- SaleItem 1. Choose SaleItem. It has status conditions that need to be tracked 2. List the states and exit transitions THE UNIVERSITY OF WINNIPEG - ACS 2913 12 RMO – Creating a State Machine Diagram Steps -- SaleItem 3. Build fragments – see figure below 4. Sequence in correct order – see figure below 5. Look for concurrent paths – none THE UNIVERSITY OF WINNIPEG - ACS 2913 13 RMO – Creating a State Machine Diagram Steps -- SaleItem 6. Add other required transitions 7. Expand with guard, action-expressions etc. 8. Review and test Below is the final State Machine Diagram THE UNIVERSITY OF WINNIPEG - ACS 2913 14 RMO – Creating a State Machine Diagram Steps -- InventoryItem 1. Choose InventoryItem. It has status conditions that need to be tracked 2. List the states and exit transitions THE UNIVERSITY OF WINNIPEG - ACS 2913 15 RMO – Creating a State Machine Diagram Steps -- InventoryItem 3. Build fragments – see figure below 4. Sequence in correct order – see figure below 5. Look for concurrent paths – see figure below THE UNIVERSITY OF WINNIPEG - ACS 2913 16 RMO – Creating a State Machine Diagram Steps -- InventoryItem 6. Add other required transitions 7. Expand with guard, action-expressions etc. 8. Review and test Below is the final State Machine Diagram THE UNIVERSITY OF WINNIPEG - ACS 2913 17 Process Sale - use case 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. THE UNIVERSITY OF WINNIPEG - ACS 2913 18 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. Four States: active overdrawn closed deleted THE UNIVERSITY OF WINNIPEG - ACS 2913 19 Bank Account Example An account begins by being Active. Once in the Active state, the account can remain active, become overdrawn, or be closed. THE UNIVERSITY OF WINNIPEG - ACS 2913 20 Bank Account Example THE UNIVERSITY OF WINNIPEG - ACS 2913 21 Bank Account Example THE UNIVERSITY OF WINNIPEG - ACS 2913 22 Bank Account Example THE UNIVERSITY OF WINNIPEG - ACS 2913 23

Use Quizgecko on...
Browser
Browser