Composition and Polymorphism
Last updated
class Shape:
def draw(self):
raise NotImplementedError()
class Circle(Shape):
def draw(self):
print("Drawing a circle")
class Square(Shape):
def draw(self):
print("Drawing a square")
def render(shape: Shape):
shape.draw()
# Polymorphic use
render(Circle()) # Drawing a circle
render(Square()) # Drawing a square