• 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

Code that correctly implements association navigation

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In section 3 of the SCJA objectives, it indicates that you need to develop "code that correctly implements association navigation."

I have searched this topic on this site and there is no code examples that help. Can anybody provide some code that illustrates this? (I'm specifically curious about the navigation part). When looking at code, how can you identify/determine that it's truly one-way or bidirectional navigation?

Thanks!
Jason
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The implementation of an association would really be one class maintaining an instance variable that references the other, associated, class.

The association is navigable if there is a getter.

So, a Player(s) is on a Team. A Team has a player instance, and a player has a Team instance. But, only the Team has a getter for the Player(s), and a player has no getter for the Team. The association is implemented both ways, but it is only navigable through the Team to the Player.

Does that make sense? I would agree that the wording in the Java Associate objectives reads a little awkward.

-Cameron McKenzie
 
Jason Scarano
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, thanks for the quick reply! Your explanation is helpful and I also found an example (below) that may help illustrate this "association navigation" relationship (from Rob Martin at informit.com). Anyone object to the below example as a model to illustrate the answer to this SCJA objective?

 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I object! I object!



The big deal is the getters. You need a getter for the button. Right now, without the getter, the class is NOT navigable, because there is no public getter which allows you to navigate to it.

itsButton is helpful from a learning point of view. I would consider it a 'bad naming practice' in a production environment. When you reference an instance variable in code, you should say this.button or this.firstName. The 'this' ends up being the equivalent of 'its', and it doesn't read correctly to say 'this.itsButton'. It's redundant. And even worse, it's redundant.

Check out my SCJA mock exams on OOA and OOD (see my signature links). There are some examples in those practice Associate Exams that deal with navigation and other Object Oriented concepts that are seen on the Sun Certified Java Associate exam.

-Cameron McKenzie
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you have a tip for this example:

You have to classes A and B: An open arrow (UML) from class A points to class B.
There is a multiplicity-value of '1' at the class A (beginning of arrow) and a value of '*' at the class B:

Now the question is, which code correctly implements this relation:

1.
class A {
private B[] b; }

class B {}

2.
class A {
private B[] b; }

class B {
private A a;
}


I'd thought, the correct answer was 2., but someone said 1. is the right one???

Grettings
Syb.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sybyll Jones wrote:Maybe you have a tip for this example:

You have to classes A and B: An open arrow (UML) from class A points to class B.
There is a multiplicity-value of '1' at the class A (beginning of arrow) and a value of '*' at the class B:

Now the question is, which code correctly implements this relation:

1.
class A {
private B[] b; }

class B {}

2.
class A {
private B[] b; }

class B {
private A a;
}


I'd thought, the correct answer was 2., but someone said 1. is the right one???

Grettings
Syb.



I believe the answer is 1 because the arrow pointing from class A to class B means that A knows about the members of B, but B knows nothing about A.

Hope this helps.
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic