Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Associations, compositions  RSS feed

Alexander Bunkenburg
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello people!

I am preparing for th SCJA exam. In fact, I am preparing all our team.

I have some questions about this exam objective:

"Develop code that implements simple class associations, code that implements multiplicity using arrays, and recognize code that implements compositions as opposed to simple associations, and code that correctly implements association navigation."

I know what association and composition are. I would implement multiplicity N using arrays (or List) following the JavaBeans conventions for indexed properties, described at indexed property.

Would that be correct for the exam?

How do I recognize compositions as opposed to simple associations? Maybe I don't understand the question properly. I would implement them the same.

How do I correctly implement association navigation? I think with a JavaBean with an indexed property, the client can navigate to the associated other object. Is that correct for the exam?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Association is a simple relationship between two objects. We see association everywhere in Java. One class having an instance variable representing another class would indicate simple association.

Navigation indicates the abbility to access a 'contained' object through the 'containing' object. Essentially, a getter method would indicate navigability.

Composition on the other hand indicates that one object has strong control over the lifecycle of another object - composition goes one step beyond association.

So, my car is associated with a parking spot. Furthermore, a parking spot is associated with my car. If my car blows up, the parking spot lives on, and if the parking spot is repaved or torn up, nothing bad should happen to my car. This is a simple association. My car has-a parking spot, and a parking spot is associated with a car.

On the other hand, a building is composed of rooms - there is a strong lifecycle relationship between the two. If Tyler Durden blew up a building, all of the rooms would be blown up as well - the lifecycle of the two is tightly intertwined.

These are the concepts you should be familiar with in order to pass the SCJA exam.


-Cameron McKenzie
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!