diff --git a/state/README.md b/state/README.md index a8dd2b5fc..7ee201be2 100644 --- a/state/README.md +++ b/state/README.md @@ -9,15 +9,21 @@ tags: --- ## Also known as + Objects for States ## Intent -Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. + +Allow an object to alter its behavior when its internal state changes. The object will appear to +change its class. ## Explanation + Real world example -> 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. +> 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. In plain words @@ -25,7 +31,10 @@ In plain words Wikipedia says -> 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. +> 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. **Programmatic Example** @@ -126,17 +135,23 @@ And here is the full example how the mammoth behaves over time. mammoth.observe(); mammoth.timePasses(); mammoth.observe(); - - // The mammoth gets angry! - // The mammoth is furious! - // The mammoth calms down. - // The mammoth is calm and peaceful. +``` + +Program output: + +```java + The mammoth gets angry! + The mammoth is furious! + The mammoth calms down. + The mammoth is calm and peaceful. ``` ## Class diagram -![alt text](./etc/state_1.png "State") + +![alt text](./etc/state_urm.png "State") ## Applicability + Use the State pattern in either of the following cases * An object's behavior depends on its state, and it must change its behavior at run-time depending on that state diff --git a/state/etc/state.png b/state/etc/state.png deleted file mode 100644 index fb1648238..000000000 Binary files a/state/etc/state.png and /dev/null differ diff --git a/state/etc/state.ucls b/state/etc/state.ucls deleted file mode 100644 index e0be8d712..000000000 --- a/state/etc/state.ucls +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/state/etc/state_1.png b/state/etc/state_1.png deleted file mode 100644 index 112bb9aff..000000000 Binary files a/state/etc/state_1.png and /dev/null differ