Skip to content

Commit 9cbc509

Browse files
committed
Update README.md
1 parent 9c648cb commit 9cbc509

File tree

4 files changed

+24
-89
lines changed

4 files changed

+24
-89
lines changed

state/README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,32 @@ tags:
99
---
1010

1111
## Also known as
12+
1213
Objects for States
1314

1415
## Intent
15-
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
16+
17+
Allow an object to alter its behavior when its internal state changes. The object will appear to
18+
change its class.
1619

1720
## Explanation
21+
1822
Real world example
1923

20-
> When observing a mammoth in its natural habitat it seems to change its behavior based on the situation. It may first appear calm but over time when it detects a threat it gets angry and dangerous to its surroundings.
24+
> When observing a mammoth in its natural habitat it seems to change its behavior based on the
25+
> situation. It may first appear calm but over time when it detects a threat it gets angry and
26+
> dangerous to its surroundings.
2127
2228
In plain words
2329

2430
> State pattern allows an object to change its behavior.
2531
2632
Wikipedia says
2733

28-
> The state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a strategy through invocations of methods defined in the pattern's interface.
34+
> The state pattern is a behavioral software design pattern that allows an object to alter its
35+
> behavior when its internal state changes. This pattern is close to the concept of finite-state
36+
> machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a
37+
> strategy through invocations of methods defined in the pattern's interface.
2938
3039
**Programmatic Example**
3140

@@ -126,17 +135,23 @@ And here is the full example how the mammoth behaves over time.
126135
mammoth.observe();
127136
mammoth.timePasses();
128137
mammoth.observe();
129-
130-
// The mammoth gets angry!
131-
// The mammoth is furious!
132-
// The mammoth calms down.
133-
// The mammoth is calm and peaceful.
138+
```
139+
140+
Program output:
141+
142+
```java
143+
The mammoth gets angry!
144+
The mammoth is furious!
145+
The mammoth calms down.
146+
The mammoth is calm and peaceful.
134147
```
135148

136149
## Class diagram
137-
![alt text](./etc/state_1.png "State")
150+
151+
![alt text](./etc/state_urm.png "State")
138152

139153
## Applicability
154+
140155
Use the State pattern in either of the following cases
141156

142157
* An object's behavior depends on its state, and it must change its behavior at run-time depending on that state

state/etc/state.png

-17.3 KB
Binary file not shown.

state/etc/state.ucls

Lines changed: 0 additions & 80 deletions
This file was deleted.

state/etc/state_1.png

-33.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)