The benefits of the object-oriented approach should be clear by now. We can design our objects (Asteroid, Ship, and so on) with a simple and intuitive API. Our objects track their own state and update themselves when we ask them to (in their update functions). They can also easily be drawn to the canvas in the correct position with a simple function call (their draw functions). The game loop itself can update all our objects in turn and then draw them all. We should be able to read the high-level code without too much trouble. All the nitty-gritty details are delegated to the objects themselves.
In this chapter, we’ll practice using objects in this way with a familiar example.