View
9
Download
0
Category
Preview:
Citation preview
ACS2913 Software Requirements Analysis and Design Instructor: Victor Balogun
OBJECT BEHAVIOR
THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2019 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.
2SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
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.
3THE UNIVERSITY OF WINNIPEG – ACS 2913 FALL 2017
State Machine DiagramState 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
4SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
State Machine for a Printer
Syntax of transition statement
◦ transition-name (parameters, …) [guard-condition] / action-expression5SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
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
6SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
Composite States
State containing other states and transitions
Printer can be On and either Idle or Working
7SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
Concurrent Paths
Multiple paths in composite state◦ Printer On paths are independent
8SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
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.
9SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
Creating a State Machine DiagramSteps
1. Review the class diagram and select classes that might require state machine diagrams
2. For each class, make a list of status conditions (states) you can identify
3. Begin building diagram fragments by identifying transitions that cause an object to leave the identified state
4. Sequence these states in the correct order and aggregate combinations into larger fragments
5. Review paths and look for independent, concurrent paths
6. Look for additional transitions and test both directions
7. Expand each transition with appropriate message event, guard condition, and action expression
8. Review and test the state machine diagram for the class
◦ Make sure state are really state for the object in the class
◦ Follow the life cycle of an object coming into existence and being deleted
◦ Be sure the diagram covers all exception condition
◦ Look again for concurrent paths and composite states
SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL RIGHTS RESERVED.
10
RMO – Creating a State Machine DiagramSteps -- SaleItem
1. Choose SaleItem. It has status conditions that need to be tracked
2. List the states and exit transitions
11SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
RMO – Creating a State Machine DiagramSteps -- SaleItem
3. Build fragments – see figure below
4. Sequence in correct order – see figure below
5. Look for concurrent paths – none
12SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
RMO – Creating a State Machine DiagramSteps -- SaleItem
6. Add other required transitions
7. Expand with guard, action-expressions etc.
8. Review and test
Below is the final State Machine Diagram
13SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
RMO – Creating a State Machine DiagramSteps -- InventoryItem
1. Choose InventoryItem. It has status conditions that need to be tracked
2. List the states and exit transitions
14SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
RMO – Creating a State Machine DiagramSteps -- InventoryItem
3. Build fragments – see figure below
4. Sequence in correct order – see figure below
5. Look for concurrent paths – see figure below
15SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
RMO – Creating a State Machine DiagramSteps -- InventoryItem
6. Add other required transitions
7. Expand with guard, action-expressions etc.
8. Review and test
Below is the final State Machine Diagram
16SYSTEMS ANALYSIS AND DESIGN IN A CHANGING WORLD, 7TH EDITION – CHAPTER 4 ©2016. CENGAGE LEARNING. ALL
RIGHTS RESERVED.
Use Case to Process a Sale
THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2016 17
We can construct a State Machne Diagram showing states for this use case
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 2016 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.
THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2016 19
Four States:
active
overdrawn
closed
deleted
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 2016 20
Bank Account Example
THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2016 21
Bank Account Example
THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2016 22
Bank Account Example
THE UNIVERSITY OF WINNIPEG - ACS 2913 - FALL 2016 23
Recommended