|
Question
|
What is an association class?
|
|
Topics
|
Process:UML
|
|
Author
|
John Moore PREMIUM
|
|
Created
|
Jul 12, 2000
|
Modified
|
Jul 12, 2000
|
|
Answer
An association class is used to model an
association as a class. Association classes often
occur in many-to-one and many-to-many associations
where the association itself has attributes.
As an example, consider a many-to-many association
between classes Person and Company. The association
could have properties; e.g., salary,
jobClassification, startDate, etc. In this case,
the association is more correctly modeled as an
association class with attributes rather than
trying to fold the attributes into one of the
classes in the association.
An association class is rendered by a dashed
line from the association to the class rectangle.
Each link in the association is an object of
the association class. An association class is
essentially a class attached to an association;
the association itself is modeled as a class.
Here are some pointers to consider when
modeling with association classes:
-
You cant attach the same class to more
than one association; an association class
is the association.
-
The name of the association is usually omitted
since it is considered to be the same as that
of the attached class.
-
Distinguish between the use of an association class
as a modeling technique and the implementation of
the association class. There can be several ways
to implement an association class.
Is this item
helpful? yes no
Previous votes Yes: 2 No: 1
|
|
Comments and alternative answers
 |
I usually implement an association class in following...
Andrei Lopatenko, Sep 4, 2000
I usually implement an association class in following way.
If we have relations between Persons and Classes
then I declare (in a simplest way)
interface CanBeAssociated {
public addAssociation(Association assoc);
}
class Person implements CanBeAssociated{
...
private Vector Associations;
public addAssociation(Association assoc){
...
}
}
class Class implements CanBeAssociated{
private Vector Associations;
public addAssociation(Association assoc){
...
}
}
class cAssociation extends UML.Association {
addSource(CanBeAssociated source) {
...
source.addAssociation(this);
}
addTarget(CanBeAssociated target) {
...
target.addAssociation(this);
}
}
For associations I create
obj assoc = new cAssociation();
assoc.addSource(person1);
assoc.addTarget(class1);
assoc.addTarget(class2);
...
Of course this is only a sketch.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
|
|
 |
|