A drawing window may contain rectangles, squares, and circles. Its drawing code should not need a separate loop for each kind of shape. Polymorphism lets it call the same method on every object while each object supplies the appropriate behavior. section 4.1.4
The shapes share an IS-A relationship with Shape. Shape declares an abstract draw() method with no drawing behavior. Rectangle implements draw(); Square inherits Rectangle’s implementation, with its height and width constrained to make a square; Circle supplies its own implementation. The shared method name lets the display treat them all as shapes without ignoring their differences. section 4.1.4
def on_draw(self):
# Clear the screen and start drawing
arcade.start_render()
# Draw the rectangles
for shape in self.shapes:
shape.draw()
The display loops over its shapes and calls shape.draw() for each one. The loop stays the same whether the next object is a rectangle, square, or circle. section 4.1.4
This is useful when a collection contains different kinds of object that share an operation. Another shape derived from Shape can join the drawing loop so long as it supports a draw() method that renders it. The display remains focused on when to draw; each shape remains responsible for how it draws. section 4.1.4








