• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HFE page 426

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sany,
Oh -- well in that case you're right.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think b2 should not have a getFoo() method.
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.oreilly.com/catalog/hfjejb/errata/hfjejb.unconfirmed
p:432, Q:4 error.
 
Leon Chen
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vishwa, that is unconfirmed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic