OO issues in python
hat at se-126.se.wtb.tue.nl
Wed Dec 17 12:48:18 CET 2003
On Wed, 17 Dec 2003 11:23:33 +0100, Ali El Dada <eldada at mdstud.chalmers.se> wrote:
> 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?
Correct, although I don't rally see why this is important.
> 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
You mean inheritance here, as in
> 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"
Sharing is normally in one direction only, ie from Father to Child,
afaik in both cases (both member-of and inheritance).
Normally, one would write Child without being aware of Father, that is,
Child should be written as a stand-alone, so it may be used in arbitrary
contexts, such as
> 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 :(
You are trying to do something that is contradictionary to the OO idea.
Luckily, that does not mean it is impossible to do.
If the parent and the child class need to share data, you either put the
data in the sub-class (ie Child), or you create a new class that holds
the data where both the parent and the child have access to.
Imho the first solution is preferrable because of a well-defined
ownership of the data.
Unlike popular belief, the .doc format is not an open publically available format.
More information about the Python-list