Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d09ae11

Browse files
committed
faif#184 - Added description of the Decorator pattern.
1 parent 3a89cf7 commit d09ae11

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

structural/decorator.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
#!/usr/bin/env python
22
"""
3-
Reference: https://en.wikipedia.org/wiki/Decorator_pattern
3+
*What is this pattern about?
4+
The Decorator pattern is used to dinamically add a new feature to an
5+
object without changing its implementation. It differs from
6+
inheritance because the new feature is added only to that particular
7+
object, not to the entire subclass.
8+
9+
*What does this example do?
10+
This example shows a way to add formatting options (boldface and
11+
italic) to a text by appending the corresponding tags (<b> and
12+
<i>). Also, we can see that decorators can be applied one after the other,
13+
since the original text is passed to the bold wrapper, which in turn
14+
is passsed to the italic wrapper.
15+
16+
*Where is the pattern used practically?
17+
The Grok framework uses decorators to add functionalities to methods,
18+
like permissions or subscription to an event:
19+
http://grok.zope.org/doc/current/reference/decorators.html
20+
21+
*References:
22+
https://sourcemaking.com/design_patterns/decorator
423
"""
524

625

0 commit comments

Comments
 (0)