• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFE page 426

 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question no. 4
Given the following container-manager unidirectional relationship
Foo(0-1) -> Bar(0-1)
And the object realtions:
f1 -> b1
f2 -> b2
What will be true after the following code runs ?
f2.setBar(f1.getBar());
A. f1.getBar() == null;
B. b2.getFoo() == null;
C. b1.getBar() == null;
D. None of the above
I got the answer right first time. A & B.
But when I thought about it again can we have b2.getFoo(). It is a "unidirectional" relationship and Foo has a field for Bar. Can Bar have a field for Foo too?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sany,
The whole point of the question is to test your knowledge of what happens when you take members of one association and put it in another one. In this case, since it's a 1-to-1 association, taking b1 and associating it with f2 disassociates b2 from any f-object and disassociates f1 from any b-object.
So, f1.getBar() == null, f2.getBar() == b1. B-objects don't have any links to their associated f-object, so b2.getFoo() doesn't mean anything. B-objects also don't have any association with other B-objects, so b1.getBar() doesn't have any meaning either.
In the end, the answer is A. B and C are false because they would be syntactically invalid given the unidirectional nature and structure of the question. D is incorrect since A is correct. Therefore, only A is correct.
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly!! That's my point. But the book says both A & B are correct. That is the reason I am confused. As I mentioned, when I looked at it the second time, I thought only A should be correct given the unidirectional nature of the relationship.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sany,
Oh -- well in that case you're right.
 
Leon Chen
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think b2 should not have a getFoo() method.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
 
Leon Chen
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishwa, that is unconfirmed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic