Skip to content

Commit 2d4712a

Browse files
authored
Merge pull request faif#213 from egens/add-tldr-comments
Add tl;dr80 comment for most of the patterns.
2 parents 345d4e4 + e31a435 commit 2d4712a

31 files changed

+146
-24
lines changed

‎behavioral/catalog.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
34
"""
45
A class that uses different static function depending of a parameter passed in
56
init. Note the use of a single dictionary instead of multiple conditions
67
"""
8+
79
__author__="Ibrahim Diop <[email protected]>"
810

911

‎behavioral/chain.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
"""http://www.dabeaz.com/coroutines/"""
3+
4+
"""
5+
http://www.dabeaz.com/coroutines/
6+
"""
47

58
fromcontextlibimportcontextmanager
69
importos

‎behavioral/command.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
4+
"""
5+
*TL;DR80
6+
Encapsulates all information needed to perform an action or trigger an event.
7+
"""
8+
39
from __future__ importprint_function
410
importos
511
fromos.pathimportlexists

‎behavioral/iterator.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
34
"""
45
http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
56
Implementation of the iterator pattern with a generator
7+
8+
*TL;DR80
9+
Traverses a container and accesses the container's elements.
610
"""
711

812
from __future__ importprint_function

‎behavioral/mediator.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
"""http://web.archive.org/web/20120309135549/http://dpip.testingperspective.com/?p=28"""
3+
4+
"""
5+
http://web.archive.org/web/20120309135549/http://dpip.testingperspective.com/?p=28
6+
7+
*TL;DR80
8+
Encapsulates how a set of objects interact.
9+
"""
410

511
importrandom
612
importtime

‎behavioral/memento.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
"""http://code.activestate.com/recipes/413838-memento-closure/"""
3+
4+
"""
5+
http://code.activestate.com/recipes/413838-memento-closure/
6+
7+
*TL;DR80
8+
Provides the ability to restore an object to its previous state.
9+
"""
410

511
fromcopyimportcopy
612
fromcopyimportdeepcopy

‎behavioral/observer.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
4+
"""
5+
http://code.activestate.com/recipes/131499-observer-pattern/
6+
7+
*TL;DR80
8+
Maintains a list of dependents and notifies them of any state changes.
9+
"""
10+
311
from __future__ importprint_function
4-
"""http://code.activestate.com/recipes/131499-observer-pattern/"""
512

613

714
classSubject(object):

‎behavioral/specification.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
34
"""
45
@author: Gordeev Andrey <[email protected]>
56
6-
Specification provide recombination business logic by
7-
chaining together using boolean logic
7+
*TL;DR80
8+
Provides recombination business logic by chaining together using boolean logic.
89
"""
910

1011
fromabcimportabstractmethod

‎behavioral/state.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
"""Implementation of the state pattern"""
43

5-
# http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
4+
"""
5+
Implementation of the state pattern
6+
7+
http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
8+
9+
*TL;DR80
10+
Implements state as a derived class of the state pattern interface.
11+
Implements state transitions by invoking methods from the pattern's superclass.
12+
"""
13+
614
from __future__ importprint_function
715

816

‎behavioral/strategy.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
34
"""
45
http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern
56
-written-in-python-the-sample-in-wikipedia
@@ -9,7 +10,11 @@
910
http://en.wikipedia.org/wiki/Strategy_pattern), however Python supports
1011
higher-order functions and allows us to have only one class and inject
1112
functions into it's instances, as shown in this example.
13+
14+
*TL;DR80
15+
Enables selecting an algorithm at runtime.
1216
"""
17+
1318
importtypes
1419

1520

0 commit comments

Comments
(0)