File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
-
4
- """http://ginstrom.com/scribbles/2008/11/06/generic-adapter-class-in-python/"""
3
+ """
4
+ *What is this pattern about?
5
+ The Adapter pattern provides a different interface for a class. We can
6
+ think about it as a cable adapter that allows you to charge a phone
7
+ somewhere that has outlets in a different shape. Following this idea,
8
+ the Adapter pattern is useful to integrate classes that couldn't be
9
+ integrated due to their incompatible interfaces.
10
+
11
+ *What does this example do?
12
+
13
+ The example has classes that represent entities (Dog, Cat, Human, Car)
14
+ that make different noises. The Adapter class provides a different
15
+ interface to the original methods that make such noises. So the
16
+ original interfaces (e.g., bark and meow) are available under a
17
+ different name: make_noise.
18
+
19
+ *Where is the pattern used practically?
20
+ The Grok framework uses adapters to make objects work with a
21
+ particular API without modifying the objects themselves:
22
+ http://grok.zope.org/doc/current/grok_overview.html#adapters
23
+
24
+ *References:
25
+ http://ginstrom.com/scribbles/2008/11/06/generic-adapter-class-in-python/
26
+ https://sourcemaking.com/design_patterns/adapter
27
+ http://python-3-patterns-idioms-test.readthedocs.io/en/latest/ChangeInterface.html#adapter
28
+ """
5
29
6
30
7
31
class Dog (object ):
You can’t perform that action at this time.
0 commit comments