mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 10:58:42 +00:00
docs: update state
This commit is contained in:
+7
-4
@@ -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
|
||||
|
||||

|
||||
|
||||
## 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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user