📘 State Machines and State Diagrams (OOAD)
🔹 1. Definition
A State Machine (Finite State Machine) is a behavioral model that describes how an object changes its state in response to events over time.
👉 Simple idea:
It shows what an object is doing at any point in time and how it moves from one condition to another.
A State Diagram (UML State Machine Diagram) is the graphical representation of this behavior.
🔹 2. Key Idea
- Objects do not behave the same all the time
- They exist in different states
- Events cause transitions between states
🔹 3. Real-Life Example
👉 Example: ATM Machine
- Idle → Card Inserted → PIN Entered → Transaction → Idle
Each step is a state, and actions move it forward.
🔹 4. Components of State Machine Diagram ⭐
🔸 4.1 State
A condition or situation of an object.
Example:
- Idle
- Processing
- Active
- Locked
📌 Represented as rounded rectangles.
🔸 4.2 Initial State
- Starting point of the system
- Shown as a black dot (●)
🔸 4.3 Final State
- End of process
- Shown as a bullseye (◎)
🔸 4.4 Transition
- Movement from one state to another
- Triggered by an event
Example:
Idle → (Insert Card) → Active
🔸 4.5 Event
- Something that causes a change
Example:
- Button press
- Login request
- Timeout
🔸 4.6 Action
- Activity performed during transition
🔹 5. State Diagram Notation
● → Initial State
○ → Final State
[State] → Rounded rectangle
→ → Transition arrow
🔹 6. Example: ATM System ⭐
🔹 States:
- Idle
- Card Inserted
- PIN Verification
- Transaction
- Exit
🔹 Transitions:
Idle → Insert Card → Card Inserted
Card Inserted → Enter PIN → PIN Verification
PIN Verification → Success → Transaction
Transaction → Finish → Idle
🔹 7. Example Diagram Description
- Start at Idle (●)
- Card inserted → move to next state
- PIN entered → system verifies
- Transaction happens
- Ends or returns to Idle
🔹 8. Types of States
🔸 8.1 Simple State
🔸 8.2 Composite State
🔸 8.3 Concurrent State
- Multiple states active at the same time
🔹 9. State vs Activity Diagram
| Feature |
State Diagram |
Activity Diagram |
| Focus |
Object states |
Workflow/process |
| Behavior |
Event-driven |
Action-driven |
| Level |
Object level |
System level |
🔹 10. Where State Diagrams are Used
- ATM systems
- Traffic lights
- Online shopping carts
- Vending machines
- User login systems
🔹 11. Advantages of State Diagrams
- Shows dynamic behavior clearly
- Helps in system understanding
- Useful for real-time systems
- Detects invalid states
- Improves design accuracy
🔹 12. Important Rules / Guidelines
- Identify all possible states first
- Define events carefully
- Avoid unnecessary states
- Ensure all transitions are valid
- Always define initial and final state
🔹 13. Likely Exam Questions
- Define state machine in OOAD.
- What is a state diagram?
- Explain components of state machine diagram.
- Draw state diagram of ATM system.
- Difference between state and activity diagram.
- What is a transition?
- Explain initial and final state.
- What are events in state diagrams?
- Types of states in UML.
- Advantages of state diagrams.
🔹 14. Quick Revision Summary 🧠
- State Machine = Behavior of object over time
- State = Condition of object
- Event = Trigger for change
- Transition = Movement between states
👉 Trick to Remember:
"SET" → State, Event, Transition