added brief descriptions of behavioral patterns
This commit is contained in:
16
README.md
16
README.md
@@ -67,6 +67,8 @@ Patterns which deal with communication between objects.
|
|||||||
___
|
___
|
||||||
##### Chain of Responsibility Pattern
|
##### Chain of Responsibility Pattern
|
||||||
|
|
||||||
|
Pass a request along a chain of objects until the request is handled.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.chain import Chain, ChainLink
|
from pypattyrn.behavioral.chain import Chain, ChainLink
|
||||||
|
|
||||||
@@ -133,6 +135,8 @@ assert "Fail" == chain.handle('handle_four')
|
|||||||
```
|
```
|
||||||
##### Command Pattern
|
##### Command Pattern
|
||||||
|
|
||||||
|
Encapsulate information for performing an action into an object.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.command import Receiver, Command, Invoker
|
from pypattyrn.behavioral.command import Receiver, Command, Invoker
|
||||||
|
|
||||||
@@ -197,6 +201,8 @@ assert "Temperature lowered by 5 degrees" == worker.undo() # Undo the previous c
|
|||||||
|
|
||||||
##### Iterator Pattern
|
##### Iterator Pattern
|
||||||
|
|
||||||
|
A way of sequentially accessing elements in a collection.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.iterator import Iterable, Iterator
|
from pypattyrn.behavioral.iterator import Iterable, Iterator
|
||||||
|
|
||||||
@@ -228,6 +234,8 @@ for count in counter_iterator: # You can loop through it how you would expect.
|
|||||||
|
|
||||||
##### Mediator Pattern
|
##### Mediator Pattern
|
||||||
|
|
||||||
|
An intermediary for managing communications between many objects.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.mediator import Mediator
|
from pypattyrn.behavioral.mediator import Mediator
|
||||||
|
|
||||||
@@ -284,6 +292,8 @@ assert 'bar' == cat.sound
|
|||||||
|
|
||||||
##### Memento Pattern
|
##### Memento Pattern
|
||||||
|
|
||||||
|
Save the state of an object and rollback to it at a later time.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.memento import Originator
|
from pypattyrn.behavioral.memento import Originator
|
||||||
|
|
||||||
@@ -306,6 +316,8 @@ assert 'Tom' == cat.name # The cats name was changed back to 'Tom' as expected.
|
|||||||
|
|
||||||
##### Null Object Pattern
|
##### Null Object Pattern
|
||||||
|
|
||||||
|
Encapsulate the absence of an object into an object with neutral behavior.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.null import Null
|
from pypattyrn.behavioral.null import Null
|
||||||
|
|
||||||
@@ -350,6 +362,8 @@ except:
|
|||||||
|
|
||||||
##### Observer Pattern
|
##### Observer Pattern
|
||||||
|
|
||||||
|
Notify many objects when a single object's state changes.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.observer import Observable, Observer
|
from pypattyrn.behavioral.observer import Observable, Observer
|
||||||
|
|
||||||
@@ -419,6 +433,8 @@ assert sorted(expected_state_2.keys()) == sorted(observer_3.updated_state.keys()
|
|||||||
|
|
||||||
##### Visitor Pattern
|
##### Visitor Pattern
|
||||||
|
|
||||||
|
Add new operations to an existing class without modifying it.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pypattyrn.behavioral.visitor import Visitee, Visitor
|
from pypattyrn.behavioral.visitor import Visitee, Visitor
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user