uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

Association Class Definition

An association class defines an object-oriented pattern to manage * -- * (many to many) associations when data needs to be stored about each link of that association.

An association class is a class and can have most of the items found in an ordinary class. However it always has two or more 1..many associations to other classes. These are syntactically shown as just a multiplicity (usually *, but 1..* and similar cases are allowed) and the role name of association class followed by the name of participating class and participating class role name. Another syntactical format of showing these associations is multiplicity followed by the name of the participating class (and an optional role name).

Example

// A person can attend many seminars,
// and a seminar can be attended by many people
// The relationship between Person and Seminar is thus
// many-to-many.
//
// There is, however, data to record about each ticket.
// This can be  recorded as an association class
//
// Note the following doesn't currently render
// in UmpleOnline using Correct UML association class
// notation. There are plans to fix this.
associationClass Ticket
{
  Integer ticketNumber;
  Double price = 0.0;
  
  * Person attendee;
  * Seminar;
}

class Person
{
  name;
}

class Seminar
{
  Date when;
  address;
}
      

Load the above code into UmpleOnline

 

Another Example

// The following shows the same example as using a regular class
// Instead of an association class
class Ticket
{
  Integer ticketNumber;
  Double price = 0.0;
  
  1 -- * Person attendee;
  1 -- * Seminar;
}

class Person
{
  name;
}

class Seminar
{
  Date when;
  address;
}
      

Load the above code into UmpleOnline

 

Another Example

// The following shows a 'quaternary' association, where the association
// class represents data in an association that links four classes.
class SportsPlayer {
  name;
}

class Season {
  year;
}

// e.g. goalie, forward etc.
class PlayingPosition {
  description;
}

class Team {
  name;
}

// This gathers the number of points a player gained on a particular team
// in a particular position while playing in a particular position
// To get the total points in any one category, you would have to add the points several instances
associationClass PlayerInPosition {
  Integer points;
  * SportsPlayer player;
  * Season;
  * Team;
  * PlayingPosition position;
}
      

Load the above code into UmpleOnline

 

Another Example

// The following example is a simple class that
// shows the association class
// grammar [[multiplicity]] ( ( [otherEndroleName] [type] [roleName] )
class A{
    f;
}


associationClass B{
    * A a1;
    * b2 C a2;
}


class C {
    d;
}

      

Load the above code into UmpleOnline

 

Syntax


// Associations that would be many-many can also become full-fledged classes too
// See user manual page AssociationClassDefinition
associationClassDefinition : associationClass [name] { [[associationClassContent]]* }

associationClassContent- : [[comment]]
    | [[classDefinition]]
    | [[position]]
    | [[displayColor]]
    | [[invariant]]
    | [[softwarePattern]]
    | [[depend]]
    | [[association]]
    | [[inlineAssociation]]
    | [[singleAssociationEnd]]
    | [[attribute]]
    | [[stateMachine]]
    | ;
    | [[extraCode]]

singleAssociationEnd : [[multiplicity]] ( ( [otherEndroleName] [type] [roleName] )
    | ( [type] [~roleName]? ) ) ;