You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ab4e53a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: state/README.md
+120-2Lines changed: 120 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,126 @@ tags:
12
12
Objects for States
13
13
14
14
## Intent
15
-
Allow an object to alter its behavior when its internal state
16
-
changes. The object will appear to change its class.
15
+
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
16
+
17
+
## Explanation
18
+
Real world example
19
+
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.
21
+
22
+
In plain words
23
+
24
+
> State pattern allows an object to change its behavior.
25
+
26
+
Wikipedia says
27
+
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.
29
+
30
+
**Programmatic Example**
31
+
32
+
Here is the state interface and its concrete implementations.
0 commit comments