Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3a89cf7

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

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎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)

AltStyle によって変換されたページ (->オリジナル) /