wood burning stoves 2.0*
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes Code that correctly implements association navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "Code that correctly implements association navigation " Watch "Code that correctly implements association navigation " New topic
Author

Code that correctly implements association navigation

Jason Scarano
Greenhorn

Joined: Mar 01, 2009
Posts: 3
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

Joined: Aug 26, 2006
Posts: 4968

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

Joined: Mar 01, 2009
Posts: 3
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

Joined: Aug 26, 2006
Posts: 4968

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

Joined: Dec 20, 2007
Posts: 14
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

Joined: Dec 24, 2009
Posts: 7
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.


SCJA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code that correctly implements association navigation
 
Similar Threads
association in java
association and aggregation
Need help for Many to Many association
Dislike by association.
Association and dependency