2
2
3
3
4
4
# ConcreteImplementor 1/2
5
- class DrawingAPI1 :
6
- def drawCircle (self , x , y , radius ):
5
+ class DrawingAPI1 ( object ) :
6
+ def draw_circle (self , x , y , radius ):
7
7
print ('API1.circle at {}:{} radius {}' .format (x , y , radius ))
8
8
9
9
10
10
# ConcreteImplementor 2/2
11
- class DrawingAPI2 :
12
- def drawCircle (self , x , y , radius ):
11
+ class DrawingAPI2 ( object ) :
12
+ def draw_circle (self , x , y , radius ):
13
13
print ('API2.circle at {}:{} radius {}' .format (x , y , radius ))
14
14
15
15
16
16
# Refined Abstraction
17
- class CircleShape :
18
- def __init__ (self , x , y , radius , drawingAPI ):
19
- self .__x = x
20
- self .__y = y
21
- self .__radius = radius
22
- self .__drawingAPI = drawingAPI
17
+ class CircleShape ( object ) :
18
+ def __init__ (self , x , y , radius , drawing_api ):
19
+ self ._x = x
20
+ self ._y = y
21
+ self ._radius = radius
22
+ self ._drawing_api = drawing_api
23
23
24
24
# low-level i.e. Implementation specific
25
25
def draw (self ):
26
- self .__drawingAPI . drawCircle (self .__x , self .__y , self .__radius )
26
+ self ._drawing_api . draw_circle (self ._x , self ._y , self ._radius )
27
27
28
28
# high-level i.e. Abstraction specific
29
- def resizeByPercentage (self , pct ):
30
- self .__radius *= pct
29
+ def scale (self , pct ):
30
+ self ._radius *= pct
31
31
32
32
33
33
def main ():
@@ -37,9 +37,9 @@ def main():
37
37
)
38
38
39
39
for shape in shapes :
40
- shape .resizeByPercentage (2.5 )
40
+ shape .scale (2.5 )
41
41
shape .draw ()
42
42
43
43
44
- if __name__ == " __main__" :
44
+ if __name__ == ' __main__' :
45
45
main ()
0 commit comments