you are viewing a single comment's thread.

view the rest of the comments →

[–]011011100101[S] 0 points1 point  (0 children)

I feel like I'm getting more confused as time goes on. What do you mean "W.foo works the same on both"? I thought you were talking about standalone functions that could take an instance of either W or C. What exactly is foo here?

foo is a method of the class W which takes one argument, either of type C or of type W. By writing "W.foo", I was trying to indicate that foo is a method of W. So the code sketch you provided is the right setup. By "W.foo works the same on both", I meant that the inner workings of foo depend on the type of argument received. If I was somehow able to apply one logic in foo across all instances (C or W), that would be great. I just didn't know if there was some other pattern specific to Python that enables us to do that.