Skip to content

Commit 5fc22f4

Browse files
committed
update BehavioralPatterns
1 parent 8362857 commit 5fc22f4

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

BehavioralPatterns/Strategy/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ Strategy lets the algorithm vary independently from clients that use it.
3636

3737
## Benefits
3838

39+
* Families of related algorithms
40+
* Inheritance can help factor out common functionality of the algorithm
41+
* Lets you vary the algorithm independently of its context, making it easier to understand, extend and switch algorithms at run-time.
42+
* Eliminate conditional statements for selecting desired behavior.
43+
3944
## Drawbacks
4045

46+
* Increases overall code complexity by creating multiple additional classes.
47+
* Client must be aware of the differences between strategies to pick a proper one.
48+
4149
## Example
4250

4351
![Duck App with Strategy Pattern](/Diagrams/Strategy.png)
@@ -56,3 +64,5 @@ model.PerformFly();
5664
```
5765

5866
## Relations with Other Patterns
67+
68+
- **Flyweight** - Strategy objects often make good flyweights.

BehavioralPatterns/TemplateMethod/README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ The Template Method pattern suggests to break down an alogirthm into a series of
2020

2121
The **template method** controls how subclasses redefine a behavior. This is also referred to as *inversion of control* because subclasses do no longer control how the behavior of a parent class redefined.
2222

23+
## Common Structure
24+
25+
![Common structure of template method pattern](https://upload.wikimedia.org/wikipedia/commons/2/2a/W3sDesign_Template_Method_Design_Pattern_UML.jpg)
26+
27+
* AbstractClass (CaffeineBeverage)
28+
* defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm
29+
* implements a template method defining the skeleton of an algorithm. The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.
30+
* ConcreteClass (Tea, Coffee)
31+
* implements the primitive operations ot carry out subclass-specific steps of the algorithm
32+
33+
## Collaborations
34+
35+
* ConcreteClass relies on AbstractClass to implement the invariant steps of the algorithm.
36+
2337
## Benefits
2438

2539
* Helps to eliminate code duplication
@@ -34,17 +48,7 @@ The **template method** controls how subclasses redefine a behavior. This is als
3448
* When subclasses should be able to extend the base algorithm without altering its structure.
3549
* When you have several classes that do similar things with only minor differences. When you alter one of the classes, you have to change others as well (e.g. HTML/PDF/CSV Generator follows the same data processing steps before generating the specific file format).
3650

37-
## Common Structure
38-
39-
![Common structure of template method pattern](https://upload.wikimedia.org/wikipedia/commons/2/2a/W3sDesign_Template_Method_Design_Pattern_UML.jpg)
40-
41-
* AbstractClass (CaffeineBeverage)
42-
* defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm
43-
* implements a template method defining the skeleton of an algorithm. The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.
44-
* ConcreteClass (Tea, Coffee)
45-
* implements the primitive operations ot carry out subclass-specific steps of the algorithm
46-
47-
_[Source: http://www.dofactory.com/net/template-method-design-pattern]_
51+
## Example
4852

4953
**Definition**
5054

@@ -113,6 +117,6 @@ public class Tea : CaffeineBeverage
113117

114118
## Comparison with other patterns
115119

116-
* **Factory Method**
120+
* **Factory Method** are often called by TemplateMethod.
117121

118-
* **Strategy**
122+
* **Strategy** - Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm.

0 commit comments

Comments
 (0)