Extending Pass With extends and super
Riverside Pool sells three kinds of pass, and the Python module makes the ten-swim card a kind
of Pass. Your JavaScript card is still a class of its own. In Python, Pass now has a
describe() method, the part each kind of pass fills in, and check_in() builds its line
from it:
class Pass:
def __init__(self, swimmer):
self.swimmer = swimmer
self.swims = 0
def describe(self):
return "casual swim"
def check_in(self):
self.swims += 1
name = self.swimmer.name
return f"{name} checked in ({self.describe()})"
The JavaScript Pass gains the same method, and its check-in calls this.describe() (the
whole file is further down). For Luis Ortega’s casual pass, both versions give
Luis Ortega checked in (casual swim).
In the module, the ten-swim card is a subclass, and its __init__() sets its own count before
handing the swimmer to the parent’s: