June 2017
Beginner
352 pages
8h 39m
English
Now we have the base Aircraft class we can refactor by hoisting into it other common functionality. For example, both the initializer and registration() methods are identical between the two subtypes:
class Aircraft: def __init__(self, registration): self._registration = registration def registration(self): return self._registration def num_seats(self): rows, row_seats = self.seating_plan() return len(rows) * len(row_seats)class AirbusA319(Aircraft): def model(self): return "Airbus A319" def seating_plan(self): return range(1, 23), "ABCDEF"class Boeing777(Aircraft): def model(self): return "Boeing 777" def seating_plan(self): # For simplicities sake, we ignore complex # seating arrangement for ...
Read now
Unlock full access