-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.cs
More file actions
21 lines (19 loc) · 865 Bytes
/
State.cs
File metadata and controls
21 lines (19 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace DesignPatterns.Behavioral.State;
/// <summary>
/// State Pattern
///
/// Intent: Allow an object to alter its behavior when its internal state changes.
/// The object will appear to change its class.
///
/// When to use:
/// - When an object's behavior depends on its state, and it must change its behavior at run-time
/// - When operations have large, multi-part conditional statements that depend on the object's state
///
/// Real-world analogy: A vending machine — it behaves differently depending on whether
/// you've inserted coins, selected a product, or it's out of stock.
/// </summary>
// TODO: Implement State
// 1. State interface with action methods
// 2. Concrete states (e.g., IdleState, HasCoinState, SoldState)
// 3. Context class that holds a reference to the current state
// 4. State transitions happen within concrete states