A
Ali El Dada
hi all:
in python, when a class, say Father, has a member that itself is an
instance of another class, say Child, an instance of Father actually
only has a reference to a Child, not the Child object itself, right?
because i know that in eiffel they give the programmer the 2 options,
the second being implemented with an additional keyword (expanded) so as
the eiffel documentation says,
"Consider the example of a class covering the notion of car. Many cars
share the same originating_plant , but an engine belongs to just one
car. References represent the modeling relation "knows about";
subobjects, as permitted by expanded types, represent the relation "has
part", also known as aggregation. The key difference is that sharing is
possible in the former case but not in the latter"
the reason why i'm asking is that i want my Child() instance to know
things about the parent without having to explicitly pass them as
arguments. this is not working
eg code that doesn't work:
class Father:
def __init__(self):
self.a = 'foo'
self.son = Child()
class Child:
def __init__(self):
print f.a
f = Father()
thanks for any help..
Cheers,
Ali Dada
in python, when a class, say Father, has a member that itself is an
instance of another class, say Child, an instance of Father actually
only has a reference to a Child, not the Child object itself, right?
because i know that in eiffel they give the programmer the 2 options,
the second being implemented with an additional keyword (expanded) so as
the eiffel documentation says,
"Consider the example of a class covering the notion of car. Many cars
share the same originating_plant , but an engine belongs to just one
car. References represent the modeling relation "knows about";
subobjects, as permitted by expanded types, represent the relation "has
part", also known as aggregation. The key difference is that sharing is
possible in the former case but not in the latter"
the reason why i'm asking is that i want my Child() instance to know
things about the parent without having to explicitly pass them as
arguments. this is not working
eg code that doesn't work:
class Father:
def __init__(self):
self.a = 'foo'
self.son = Child()
class Child:
def __init__(self):
print f.a
f = Father()
thanks for any help..
Cheers,
Ali Dada