https://github.com/liteobject/demo.designpattern.statemachine
https://github.com/liteobject/demo.designpattern.statemachine
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/liteobject/demo.designpattern.statemachine
- Owner: LiteObject
- Created: 2022-10-08T13:18:33.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-11T16:29:11.000Z (over 3 years ago)
- Last Synced: 2024-12-29T18:24:23.881Z (about 1 year ago)
- Language: C#
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# An Example of State Design Pattern with C#
## What is State Design Pattern?
>State is a behavioral design pattern that lets an object alter its behavior when its internal state changes.
## When can you use State Design Pattern?
* When an object needs to behave differently depending on its current state
* The number of states is enormous, and
* The state-specific logic needs to be seperated
## Components in State Design Pattern
* Context
> Stores a reference to one of the concrete state objects and delegates to it all state-specific work. The context communicates with the state object via the state interface. The context exposes a setter for passing it a new state object.
* State
> Defines interface for declaring what each concrete state should do.
* Concrete State
>Provides implementation for methods defined in State.
```mermaid
classDiagram
Context *--> State
State <|-- ConcreteStateA
State <|-- ConcreteStateB
class Context {
+Context(initialState)
+SetState(newState)
+Request()
}
class State {
<>
+Handle()
}
class ConcreteStateA {
+Handle()
}
class ConcreteStateB {
+Handle()
}
```