task: Explanations and grammar fixes for all the GoF patterns (#1791)

* Grammatical fixes to command pattern

* Update bridge pattern readme

* Fixes to builder pattern grammar

* Update chain of responsibility

* Improvements to the composite example

* Fixes to headings

* Minor updates to decorator pattern

* Update facade

* Update factory example

* Update factory method

* Update flyweight

* Interpreter explanation

* Update iterator readme

* Add explanation for mediator pattern

* Grammatical fixes to memento

* Grammar fixes for observer

* Update explanation for the prototype pattern

* Proxy pattern grammar fixes

* Update singleton

* Grammar fixes to state pattern

* Grammar fixes for strategy

* Grammar fixes, template method

* Grammar fixes for visitor

* Fix typo
This commit is contained in:
Ilkka Seppälä
2021-06-24 15:57:20 +03:00
committed by GitHub
parent bbdff14a66
commit 04bf566dc1
66 changed files with 872 additions and 357 deletions

View File

@ -17,10 +17,11 @@ structure.
## Explanation
Real world example
Real-world example
> The general steps in stealing an item are the same. First you pick the target, next you confuse
> him somehow and finally you steal the item. However there are many ways to implement these steps.
> The general steps in stealing an item are the same. First, you pick the target, next you confuse
> him somehow and finally, you steal the item. However, there are many ways to implement these
> steps.
In plain words
@ -117,7 +118,7 @@ public class HalflingThief {
}
```
And finally we show how the halfling thief utilizes the different stealing methods.
And finally, we show how the halfling thief utilizes the different stealing methods.
```java
var thief = new HalflingThief(new HitAndRunMethod());
@ -135,14 +136,14 @@ And finally we show how the halfling thief utilizes the different stealing metho
The Template Method pattern should be used
* To implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behavior that can vary
* When common behavior among subclasses should be factored and localized in a common class to avoid code duplication. This is good example of "refactoring to generalize" as described by Opdyke and Johnson. You first identify the differences in the existing code and then separate the differences into new operations. Finally, you replace the differing code with a template method that calls one of these new operations
* When common behavior among subclasses should be factored and localized in a common class to avoid code duplication. This is a good example of "refactoring to generalize" as described by Opdyke and Johnson. You first identify the differences in the existing code and then separate the differences into new operations. Finally, you replace the differing code with a template method that calls one of these new operations
* To control subclasses extensions. You can define a template method that calls "hook" operations at specific points, thereby permitting extensions only at those points
## Tutorial
## Tutorials
* [Template-method Pattern Tutorial](https://www.journaldev.com/1763/template-method-design-pattern-in-java)
## Real world examples
## Known uses
* [javax.servlet.GenericServlet.init](https://jakarta.ee/specifications/servlet/4.0/apidocs/javax/servlet/GenericServlet.html#init--):
Method `GenericServlet.init(ServletConfig config)` calls the parameterless method `GenericServlet.init()` which is intended to be overridden in subclasses.