mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 04:15:07 +00:00
docs: updates to several patterns
This commit is contained in:
1 parent
4652842c94
commit
584e949714
70 files changed
+347
-479
No files matched your search
+2
-6
@@ -15,7 +15,7 @@ Balking Pattern is used to prevent an object from executing a certain code if it
|
||||
|
||||
## Explanation
|
||||
|
||||
Real world example
|
||||
Real-world example
|
||||
|
||||
> A real-world analogy of the Balking design pattern can be seen in a laundry service. Imagine a washing machine at a laundromat that only starts washing clothes if the door is properly closed and locked. If a user tries to start the machine while the door is open, the machine balks and does nothing. This ensures that the washing process only begins when it is safe to do so, preventing water spillage and potential damage to the machine. Similarly, the Balking pattern in software design ensures that operations are only executed when the object is in an appropriate state, preventing erroneous actions and maintaining system stability.
|
||||
|
||||
@@ -31,7 +31,7 @@ Wikipedia says
|
||||
|
||||
There's a start-button in a washing machine to initiate the laundry washing. When the washing machine is inactive the button works as expected, but if it's already washing the button does nothing.
|
||||
|
||||
In this example implementation, `WashingMachine` is an object that has two states in which it can be: ENABLED and WASHING. If the machine is ENABLED, the state changes to WASHING using a thread-safe method. On the other hand, if it already has been washing and any other thread executes `wash()`it won't do that and returns without doing anything.
|
||||
In this example implementation, `WashingMachine` is an object that has two states in which it can be: ENABLED and WASHING. If the machine is ENABLED, the state changes to WASHING using a thread-safe method. On the other hand, if it already has been washing and any other thread executes `wash`it won't do that and returns without doing anything.
|
||||
|
||||
Here are the relevant parts of the `WashingMachine` class.
|
||||
|
||||
@@ -114,10 +114,6 @@ Here is the console output of the program.
|
||||
14:02:52.324 [pool-1-thread-2] INFO com.iluwatar.balking.WashingMachine - 14: Washing completed.
|
||||
```
|
||||
|
||||
## Class diagram
|
||||
|
||||

|
||||
|
||||
## Applicability
|
||||
|
||||
Use the Balking pattern when
|
||||
|
||||
Reference in new issue
Block a user