Java Reference
In-Depth Information
Idiom
Many-to-one association
Context
An n :1 association between two classes navigable from
the many role to the one role. Note that a 1 : 1 association
is just a special case of an n :1 association.
Problem
Implement the association enabling navigation.
Forces or tradeoffs
A link to the object must be stored.
It must be navigable.
Solution
An attribute contains a reference to the linked object; this
attribute is implemented according to the “read-only
attribute” idiom.
Examples
private Attribute category;
public Attribute category() { return category }
Design rationale
Since, in Java, object variables (and attributes) are
references to objects and not effective object storage, this
kind of variable lends itself to implementing links.
Idiom
One-to-many association decomposition
Context
A 1 : n association between two classes navigable from the
one role to the many role. The exact cardinality of the
association is not known in advance.
Problem
Implement the association enabling navigation.
Forces or tradeoffs
A link to the object must be stored. It must be navigable.
Arrays require knowledge of the cardinality.
Solution
The transformed association can be easily implemented
with a reference in the class One plus a reference in the
Many class: in total one attribute per class.
One
One
0 .. 1
! first
0 .. n
! many
Many
Many
! next
0 .. 1
Forces resolution
Knowledge of cardinality is not required.
We need to implement two one-to-one associations.
Design rationale
Since we know how to implement one-to-one (and many-
to-one) associations we decompose the original association
into simpler and easily implementable associations.
 
Search WWH ::




Custom Search