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

Skip to content

Commit 3a89cf7

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

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

structural/adapter.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
#!/usr/bin/env python
22
# -*- 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+
"""
529

630

731
class Dog(object):

0 commit comments

Comments
 (0)