Skip to content

Instantly share code, notes, and snippets.

@wagamama
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save wagamama/3ec31216f2ba1e4dcdfe to your computer and use it in GitHub Desktop.

Select an option

Save wagamama/3ec31216f2ba1e4dcdfe to your computer and use it in GitHub Desktop.
Clean Code - Ch. 6 Object Shape
class Shape:
def area(self):
raise Exception
class Square(Shape):
def __init__(self, side):
self._side = side
def area(self):
return self._side ** 2
class Rectangle(Shape):
def __init__(self, width, height):
self._width = width
self._height = height
def area(self):
return self._width * self._height
class Circle(Shape):
def __init__(self, radius):
self.PI = 3.14159
self._radius = radius
def area(self):
return self.PI * (self._radius ** 2)
def main():
s = Square(5)
print s.area()
r = Rectangle(3, 8)
print r.area()
c = Circle(4)
print c.area()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment