Skip to content

Commit d671429

Browse files
committed
Fixed PEP-8 discrepancy in Bridge pattern
1 parent 557677b commit d671429

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

bridge.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33

44
# 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):
77
print('API1.circle at {}:{} radius {}'.format(x, y, radius))
88

99

1010
# 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):
1313
print('API2.circle at {}:{} radius {}'.format(x, y, radius))
1414

1515

1616
# 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
2323

2424
# low-level i.e. Implementation specific
2525
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)
2727

2828
# high-level i.e. Abstraction specific
29-
def resizeByPercentage(self, pct):
30-
self.__radius *= pct
29+
def scale(self, pct):
30+
self._radius *= pct
3131

3232

3333
def main():
@@ -37,9 +37,9 @@ def main():
3737
)
3838

3939
for shape in shapes:
40-
shape.resizeByPercentage(2.5)
40+
shape.scale(2.5)
4141
shape.draw()
4242

4343

44-
if __name__ == "__main__":
44+
if __name__ == '__main__':
4545
main()

0 commit comments

Comments
 (0)