Page 238 -
P. 238

reinventing the wheel
















                                                    Emmm...maybe I’m missing something, but
                                                   isn’t your Athlete class wasteful? I mean,
                                                   you’ve extended it with functionality that’s
                                                   already in lists, which feels a little like
                                                    reinventing the wheel to me...








                                                  Yes, your Athlete class is much like a list.
                                                  Your Athlete class does indeed behave like a list most
                                                  of  the time, and you’ve added methods to expose some list
                                                  functionality to the users of your class. But it’s true: you are
                                                  reinventing the wheel here. Your add_time() method
                                                  is a thin wrapper around the list append() method and
                                                  your add_times() method is list’s extend() method in
                                                  disguise.
                                                  In fact, your Athlete class only differs from Python’s list
                                                  due to the inclusion of the name and dob object attributes.
























           202    Chapter 6
   233   234   235   236   237   238   239   240   241   242   243