File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code that correctly implements association navigation

 
Jason Scarano
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Sybyll Jones
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Brian Moran
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic