🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

ACS2913 Software Requirements Analysis and Design Instructor: David Tenjo OBJECT BEHAVIOUR THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2023 1 Object Behavior – State Machine Diagram Each class has objects that may have status conditions or “states” Object behavior consists of the various states...

ACS2913 Software Requirements Analysis and Design Instructor: David Tenjo OBJECT BEHAVIOUR THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2023 1 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 - FALL 2022 2 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 State Machine Diagram 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. THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 3 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 State Machine Diagram 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 - FALL 2022 4 State Machine for a Printer Syntax of transition statement ◦ transition-name (parameters, …) [guard-condition] / action-expression THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 5 Concurrent states – when an object is in one or more states at the same time Concurrency in a State Machine Diagram ◦ Concurrent states in a State Machine Diagram represent multiple states that can exist and operate independently at the same time. ◦ similar to multitasking in computer systems ◦ It's a way to represent parallelism and can be particularly useful in modeling software systems where multiple tasks or components need to run concurrently. THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 6 1.Main Control State: 1. States: Idle, MovingUp, MovingDown 2. Transitions: 1. Idle -> MovingUp when a passenger presses the "Up" button. 2. Idle -> MovingDown when a passenger presses the "Down" button. 3. MovingUp -> Idle when the elevator reaches the desired floor. 4. MovingDown -> Idle when the elevator reaches the desired floor. Concurrent State Example: Elevator 2.Door Control State: 1. States: Open, Closed 2. Transitions: 1. Closed -> Open when a passenger presses the "Open" button. 2. Open -> Closed when a certain amount of time has passed or when a passenger presses the "Close" button. These two sets of states (Main Control and Door Control) can exist concurrently. While the main control system is managing the elevator's movement, the door control system is handling the opening and closing of the doors. These two aspects operate independently and can transition between their respective states without affecting each other. This illustrates the concept of concurrent states, where multiple aspects of a system can function simultaneously within the same state machine. THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2023 7 Composite States State containing other states and transitions Printer can be On and either Idle or Working THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 8 Concurrent Paths Multiple paths in composite state ◦ Printer On paths are independent 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 - FALL 2022 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 - FALL 2022 10 Creating a State Machine Diagram 1 2 3 4 Review the class diagram and select classes that might require state machine diagrams For each class, make a list of status conditions (states) you can identify Build diagram fragments by identifying transitions that cause an object to leave the identified state Sequence these states in the correct order and aggregate combinations into larger fragments 5 Review paths and look for independent, concurrent paths 6 7 Look for additional transitions and test both directions Expand each transition with appropriate message event, guard condition, and action expression 8 Review and test the state machine diagram for the class ** ** •States are true states for the object in the class •Follow the life cycle of an object •Be sure the diagram covers all exception conditions •Look again for concurrent paths and composite states THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 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 - FALL 2022 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 - FALL 2022 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 - FALL 2022 14 RMO – Creating a State Machine Diagram Steps -- InventoryItem 1. 2. Choose InventoryItem. It has status conditions that need to be tracked List the states and exit transitions THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 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 - FALL 2022 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 - FALL 2022 17 Use Case to Process a Sale We can construct a State Machine Diagram showing states for this use case THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 18 Process Sale 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 - FALL 2022 19 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 - FALL 2022 20 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 - FALL 2022 21 Bank Account Example THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 22 Bank Account Example THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 23 Bank Account Example THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2022 24

Use Quizgecko on...
Browser
Browser