docs: update state

This commit is contained in:
Ilkka Seppälä
2024-05-27 12:54:23 +03:00
parent 07d56c77cf
commit f7f318ad37
2 changed files with 7 additions and 5 deletions
+7 -4
View File
@@ -49,7 +49,9 @@ public interface State {
void observe();
}
```
```java
@Slf4j
public class PeacefulState implements State {
@@ -69,7 +71,9 @@ public class PeacefulState implements State {
LOGGER.info("{} calms down.", mammoth);
}
}
```
```java
@Slf4j
public class AngryState implements State {
@@ -129,12 +133,15 @@ public class Mammoth {
Here is the full example of how the mammoth behaves over time.
```java
public static void main(String[] args) {
var mammoth = new Mammoth();
mammoth.observe();
mammoth.timePasses();
mammoth.observe();
mammoth.timePasses();
mammoth.observe();
}
```
Program output:
@@ -146,10 +153,6 @@ Program output:
The mammoth is calm and peaceful.
```
## Class diagram
![State](./etc/state_urm.png "State")
## Applicability
* An object's behavior depends on its state, and it must change its behavior at runtime depending on that state.
@@ -46,6 +46,5 @@ public class App {
mammoth.observe();
mammoth.timePasses();
mammoth.observe();
}
}