Module 2 · Line Tracking
Lesson 9 · Object Composition — Knowledge ChecksAnswer key
What does 'object composition' mean?
Composition is a 'has-a' relationship: LineTrack has-a LineSensor. It keeps each class focused on one job.
Why is there a time.sleep(0.5) at the start of turn_right(), before the while loop?
Right after starting the spin, the sensors are still on the intersection. The pause lets the robot clear it before it starts looking for the next line.
What does the `pass` inside the while loop do?
pass is a do-nothing placeholder. The motors were already told to spin; the loop simply waits, re-checking is_off_line() until a line appears.
Why can the main program be just a few method calls now?
Composition hides complexity: the classes hold the detail, so the main program reads as a clear sequence of intentions.