FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-patterns/bridge.py at master · Pythoning/python-patterns · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Pythoning
/
python-patterns
Public
forked from
faif/python-patterns
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-patterns
/
bridge.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (32 loc) · 1.08 KB
Breadcrumbs
python-patterns
/
bridge.py
Copy path
File metadata and controls
45 lines (32 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# http://en.wikibooks.org/wiki/Computer_Science_Design_Patterns/Bridge_Pattern#Python
# ConcreteImplementor 1/2
class
DrawingAPI1
(
object
):
def
draw_circle
(
self
,
x
,
y
,
radius
):
print
(
'API1.circle at {}:{} radius {}'
.
format
(
x
,
y
,
radius
))
# ConcreteImplementor 2/2
class
DrawingAPI2
(
object
):
def
draw_circle
(
self
,
x
,
y
,
radius
):
print
(
'API2.circle at {}:{} radius {}'
.
format
(
x
,
y
,
radius
))
# Refined Abstraction
class
CircleShape
(
object
):
def
__init__
(
self
,
x
,
y
,
radius
,
drawing_api
):
self
.
_x
=
x
self
.
_y
=
y
self
.
_radius
=
radius
self
.
_drawing_api
=
drawing_api
# low-level i.e. Implementation specific
def
draw
(
self
):
self
.
_drawing_api
.
draw_circle
(
self
.
_x
,
self
.
_y
,
self
.
_radius
)
# high-level i.e. Abstraction specific
def
scale
(
self
,
pct
):
self
.
_radius
*=
pct
def
main
():
shapes
=
(
CircleShape
(
1
,
2
,
3
,
DrawingAPI1
()),
CircleShape
(
5
,
7
,
11
,
DrawingAPI2
())
)
for
shape
in
shapes
:
shape
.
scale
(
2.5
)
shape
.
draw
()
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL