Greg Ewing <greg.ew...@canterbury.ac.nz> writes: > On 3/11/22 1:37 pm, Julieta Shem wrote: >> The code for computing the length of a Pair (which is really a linked >> list) happens to be the same for computing the length of a Stack. > > I would question whether that should be a method of Pair at all, > since it's not the length of the pair itself, but the length of > a structure built out of pairs.
You make a lot of sense. > But in any case, the way to do this in a conceptually clean way > is for the length method of Stack to call whatever it is that > computes the length of a linked list of Pairs. This is what > the term "delegation" refers to. Thank you for the example. I agree with you. Perhaps I can reduce the class Pair to just being a pair as we know it, made of two things, then we create a class called Sequence, which is really a composition of Pairs, comes with a length method and we derive Stack from it. -- https://mail.python.org/mailman/listinfo/python-list