Say I have the following class:
public class BodyClass{
private LegClass myLeftLeg;
private LegClass myRightLeg;
private NoseClass myNose;
...
}
later on somewhere deep in a software program, I am going to have a solitary instance of myRightLeg.
Now, how come I won't know easily (or at all) which BodyClass object this rightleg pertains to, let alone which Class this instance variable is contained in? Why is it that in composition relationships, the information about the parent class is not automatically stored in the child objects, at runtime?
Couldn't there be a world whereby Java lazily-loaded each class variable with information about the parent class itself?
Why would this be bad? And wouldn't this be a fairly solid benefit?
I hear people say things like subclasses shouldn't know anything about their superclasses and instance variables shouldn't know anything about their parent classes, but frankly I don't see why not.
My question relates to this question: