Win a copy of The Career Toolkit this week in the Jobs Discussion forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

HFE page 426

 
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?
 
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.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think b2 should not have a getFoo() method.
 
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic