3 ms·
Two nitpicky comments. > Even if, right now, we were to change it to _note2, the maintainer of A could, in any future release of A, add a new _note2 variable w
by porpoisemonkey 9y ago
Two nitpicky comments.
> Even if, right now, we were to change it to _note2, the maintainer of A could, in any future release of A, add a new _note2 variable which conflicts with something B is using.
This is why Python offers actual namespacing of properties and methods in the form of a double underscore (__). Double underscore prepends an underscore and the class name to the private property name which prevents these sorts of collisions.
class Bprime(object):
def __init__(self, a):
for var in dir(a):
setattr(self, var, getattr(a, var))
> Uh oh. Looks like composition is worse than inheritance.
This is not composition.
- akud 9y agoYea, this is actually inheritance - it's a mixin.
- gipp 9y ago> This is not composition. That's basically the author's point. > Once I understood what they meant by “composition”, I was even more surprised to find that I agreed with this assertion.
- porpoisemonkey 9y agoGood point - I think I misunderstood the purpose of the article. I'll leave the original comment as a matter of record.