Re: Why less emphasis on private data?
On 2007-01-08, Paul Rubin <httpwrote:
When faced with this situation, is there any way to proceed
besides using composition instead?
--
Neil Cerutti
We've got to pause and ask ourselves: How much clean air do we really need?
--Lee Iacocca
On 2007-01-08, Paul Rubin <httpwrote:
Dennis Lee Bieber <wlfraed@ix.net com.comwrites:
>
Interesting. I just tried that. mod1.py contains:
>
class B:
def foo(self): self.__x = 'mod1'
>
mod2.py contains:
>
class B:
def bar(self): self.__x = 'mod2'
>
And the test is:
>
from mod1 import B as B1
from mod2 import B as B2
>
class A(B1, B2): pass
>
a = A()
a.foo()
print a._B__x
a.bar()
print a._B__x
>
Sure enough, mod2 messes up mod1's private variable.
>I'd be quite concerned about the design environment rather than the
>immediate code... Probably need something ugly like...
>>
>from mod1 import B as B1
>from mod2 import B as B2
>class A(B1, B2):
> ....
>immediate code... Probably need something ugly like...
>>
>from mod1 import B as B1
>from mod2 import B as B2
>class A(B1, B2):
> ....
Interesting. I just tried that. mod1.py contains:
>
class B:
def foo(self): self.__x = 'mod1'
>
mod2.py contains:
>
class B:
def bar(self): self.__x = 'mod2'
>
And the test is:
>
from mod1 import B as B1
from mod2 import B as B2
>
class A(B1, B2): pass
>
a = A()
a.foo()
print a._B__x
a.bar()
print a._B__x
>
Sure enough, mod2 messes up mod1's private variable.
besides using composition instead?
--
Neil Cerutti
We've got to pause and ask ourselves: How much clean air do we really need?
--Lee Iacocca
Comment