an oop question

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Nov 2 21:47:31 EDT 2022


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.

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.

-- 
Greg


More information about the Python-list mailing list