In this lesson
- It starts with a question. A harbour program has Ferry, FishingBoat and Barge classes. Each kind pays a different mooring fee. One loop must charge every boat in the harbour. What is the cleanest design?
- The idea you will find. Ask every object the same way, and let each answer in its own way. — The loop you ran never checked what kind of boat it held. It sent the same call, fee(), and each object replied with its own class’s version. That is why code written this way keeps working when new kinds are added: the new class brings its own answer with it.
- How you learn it. By doing: a slider.
- Length. 6 short steps. Progress saves on this phone.
Part of Python: Classes & Objects
Classes and objects: bundling what a thing knows with what it can do.