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?
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.
Joined: Mar 01, 2009
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
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.