Page 240 -
P. 240

inherit class


           Inherit from Python’s built-in list


           Python’s class lets you create a custom class from scratch, just like you did with
           your Athlete class. However, class also lets you create a class by inheriting
           from any other existing class, including Python’s built-in data structure classes
           that provide you with list, set, and dict. Such classes are referred to as
           subclasses.
           What’s really nice is that when you inherit from an existing class (such as
          list), you are given all of the existing functionality for free.
          As your existing class is really nothing more than a list with added attributes,
           perhaps a better design is to kill off your Athlete class and replace it
           with a class that inherits from the built-in list class? It’s certainly worth
           considering, isn’t it?



                                           Sorry to hear about your
                                          Athlete class. But, according
                                          to my files, you’re in line to inherit a
                                          mountain of functionality from the
                                          built-in list class. Congratulations,
                                          you’re rich!





























                                                                          Slippery
                                                                          lawyer-type


           204    Chapter 6
   235   236   237   238   239   240   241   242   243   244   245