in the real application, they are more complicated. but they do have the structure like above: Line has Point as member, and Point has Line as member as well to make some operation easier.
my question is: is this kind of structure good? or proper? any performance, or potential problem there?
it really confuses me... as it looks like a kind of infinite reference: Line -> Point -> Line -> Point -> ...
thanks,
It all depends on the relationship between your classes. Two classes having a one-to-one relationship may refer to each other. Imagine that a person can only have one dog, and a dog can only have one loving master.
A Person called "emily" may have a Dog called "wiz". "emily" knows about "wiz" and "wiz" knows about "emily".
(I'm not discussing whether or not the design of your Point and Line classes is good or not)
We don't know what these Points and Lines are for in your application, nor do we know how they should be related.
Your design makes it so that a Point can only be in one Line. There are lots of situations where that would be wrong -- for example if a Point could be at the intersection of two Lines. But maybe that doesn't apply in your application. We can't tell.
emily li
Greenhorn
Joined: Dec 18, 2002
Posts: 6
posted
0
sorry, my bad example.
just forget the line & point. let me say just 2 objects.
A & B have some relationship. i know this design make the usage later much much easier. i can just use B.aMemberOfB (while inside B) to access the member/method of class A. but is that a good design?
does aMemberOfB keep the reference of A or a whole copy? will this design cause any performance problem?
i worked on C for a while. i know this kind of structure is not allowed in C (or maybe just hard to implement in C). that's why i comes up this question.
sorry, i didn't make myself clear. hope this help to clarify my question/concern.
thanks,
Esmaeil Ashrafi
Ranch Hand
Joined: Feb 22, 2010
Posts: 73
posted
0
emily li wrote:...
... but is that a good design?
does aMemberOfB keep the reference of A or a whole copy? will this design cause any performance problem?
i worked on C for a while. i know this kind of structure is not allowed in C (or maybe just hard to implement in C). that's why i comes up this question.
sorry, i didn't make myself clear. hope this help to clarify my question/concern.
thanks,
This post was more clear, i think. it just keeps a reference to the object instantiated from class A ( or made of A ! ) and not only cause any problem, but makes sense to interaction between objects: that's the way they can call each other!
You can just figure it out by answering the question:
how to call a method of class A from within class B ?
of course you need to have a reference to A to point to it from B (or anywhere outside A)
Look at another example i think will make more sense even:
I'm really tired of being engaged with stuff other than Java and programming
Wish to get back soon to my love...
emily li
Greenhorn
Joined: Dec 18, 2002
Posts: 6
posted
0
I see. thank you
Esmaeil Ashrafi wrote:
... ...
This post was more clear, i think. it just keeps a reference to the object instantiated from class A ( or made of A ! ) and not only cause any problem, but makes sense to interaction between objects: that's the way they can call each other!
You can just figure it out by answering the question:
how to call a method of class A from within class B ?
of course you need to have a reference to A to point to it from B (or anywhere outside A)
... ...