Tuesday, April 10, 2007

What is Association and how it maps into a Java class?

An Association specifies how objects are related to one another.To identify associations,look for verb and prepositional phrases like 'part of','next to','works for' or 'contained in'.While identifying implicit associations,a lot common sense and general knowledge is required.It is very important to eleminate redundant associations while desiging a system.The most important aspects of associations are:
Cardinality - a cardinality of one on a given relationship end generates a Java reference, for example
public class Customer
{
Purchase purchase; ...
}
A cardinality of many (depicted as a number or *) generates a Java container:

public class Customer
{
List purchases; ...
}

Navigability - For given an instance of an object on one side of a association you can access an instance on the other side. If a association can only be traversed in one direction then this will be indicated with arrows. If there are no arrows then the association is bi-directional.

Association end - A given class only sees the association through the attributes set on the association end. In other words that simple line actually represents two independent sets of data, one for each of the two classes involved. Besides the cardinality and navigability the most important attribute is the association end name. This name is used to generate the getter and setter methods and in persistent classes database column names.

The different types of associations can be Aggregation and Composition.I will describe them in more details in next blogs to come.

0 comments :

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2017. Reads: best tracker