• 8 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 5/5/22

Create Associations Between Your Classes to Retain Links Within Your Data

You've identified all of the classes and their attributes. At this stage, all the columns in the CSV file have a place in your model. So, for example, you know that all the information about the director Danny Boyle will be in the  Director  class and that the film   Steve Jobs  will be in the  Film  class.

This information is separated into two different classes. But you need to be able to indicate the link between  Steve Jobs  and its director. At this point, this link has not yet been modeled.

As you can tell, you're going to create links between classes in this chapter.

Set Up Your Associations

The next step is to create your associations. It’s best to draw lines to link your classes and give each link a name, preferably a verb, such as “directs,” “produces,” etc.

Here's the answer!
Here's the answer!

Define the Multiplicity of Your Associations

It’s essential to consider the concept of multiplicity when defining associations.

This tells you if a film can be directed by only one or many directors and inversely if a director can direct only one or many films.

There are three types of associations:

  • Many-to-many:

    • Many directors can direct one film, and one director can direct many films.

  • One-to-many or many-to-one:

    • A maximum of one production company can produce one film, and one company can produce many films.

  • One-to-one:

    • This scenario doesn't exist in your data, but it occurs when one instance of a class A can only be associated with a maximum of one instance of a class B. And one instance of B can only be associated with a maximum of one instance of A.
      For example, a movie theater has only one address, and a given address can only accommodate a single movie theater. 

Next, we’ll take multiplicity to the next level of detail.

For example, when you say “a maximum of one,” you can specify whether it's “one only” or “zero or one.” Also, “many” could mean “zero, one, or more” or “more than one,” and so on.

Here’s the notation:

A maximum of one:

Notation

Abbreviation

Meaning

0..1

(no abbreviation)

Zero or one

1..1

1

Exactly one

Many:

Notation

Abbreviation

Meaning

0..*

*

0, 1, or more

1..*

(no abbreviation)

At least one

n..n

n

Exactly n (where n is a whole number)

m..n

(no abbreviation)

At least m and at most n (where m and n are whole numbers and m<n)

Here’s how to use this notation:

  • One director can direct at least one film (notation:1..* ), and one director can direct zero, one, or many (notation:*) films:

Adding multiplicities between Film and Director
Adding multiplicities between Film and Director
  • Exactly one production company produces one film (1), and one company can produce zero, one, or many films (*): 

Multiplicity between Film and ProductionCompany
Multiplicity between Film and ProductionCompany
  • One movie theater has exactly one address (1), and one address can only accommodate zero or only one movie theater (0..1):

Multiplicity between  MovieTheater  and  Address
Multiplicity between MovieTheater and Address

Whether to have a minimum of zero or one is often debatable. For example, if a director can direct zero, one, or many films as above, there can be a director in your database not associated with any films.

If the notion of a director is central to your application’s functionality, you might decide that they can exist without having directed any films.

But if the notion of a director is secondary, there may be no point in having a one with no films. So you might choose a multiplicity of  1..*  instead of    *  .

So, here's your model with multiplicities added:

The model with added multiplicities
The model with added multiplicities

Define Your Associations Using Association Classes

Sometimes, you need to assign certain characteristics to an association.

Perhaps your instinct would be to draw a conceptual diagram (like below) instead of drawing three classes:  Film  ,  Shooting  , and  Location  , as you did previously.

Conceptual diagram
Conceptual diagram

You would have been right to do so! But if you'd done this, you wouldn't have had anywhere to place the    Start date  and  End date  columns. These two dates are the association features that link a location to a film. 

And it is possible to assign features to a link using an association class. In our example, because the association is named “is shot,” you can call your class  Shooting  : 

Adding the association class
Adding the association class

It's not very different from what we had before, though, is it?

True. These options are similar and both are acceptable. Your choice won’t make any difference when you input your model into the RDBMS.

Use Composition to Expand Your Associations

When a class is part of another class, you use a particular type of association: composition.

Take the example of an electronic circuit made up of electrical parts, including diodes, capacitors, microprocessors, etc. So, you can have a composition association between the  ElectronicCircuit  class and the  ElectronicPart  class.

Imagine that your circuit was faulty, and you had to throw it away. In this scenario, you would automatically throw away all of the parts. That’s composition: a part (a diode, for example) can only exist through its composite (electronic circuit).

You could say that a filming instance is part of a film for your application. There is no point storing a filming event in your database if you don’t know which film it’s associated with.

There could also be a composition between  Film  and  ProductionCompany  . A film can't exist if a production company hasn’t produced it. Another issue is that sometimes there could be different films with the same name. So, if you want to identify a film uniquely, you need its title and the name of its production company, which proves that there is a dependency between these two classes.

Here is how this composition would be shown (with a solid black diamond next to the composite):

Illustration of a composition
Illustration of a composition

Use composition when the following criteria apply:

  1. The composite is made up of component parts.

  2. The composition association is a one-to-many relationship because the composite can have many parts (  0..1  ,  1  ,  or  1..*   ). The part belongs to one and only one composite (the multiplicity must be 1 and nothing else): the composite is non-shareable.

  3. There is a link between the lifecycle of the composite and the component part. The part disappears when the composite object to which it belongs is deleted.

Ta-dah! Here is an exclusive preview of the latest version of your UML model!

The conceptual data model
The conceptual data model

Watch Out for Redundancy!

For example, you could be tempted to say that a director works for a production company when they direct a film. You would then have:

Conceptual diagram
Conceptual diagram

However, you can derive the  works for  association using two other associations. If you know that Woody Allen directed Take the Money and Run and the American Broadcasting Company (ABC) produced it, you can conclude that Woody Allen worked for the American Broadcasting Company.

Now it's Your Turn!

Here’s a class diagram showing musical groups (bands) performing at concerts. Determine the possible multiplicity for the associations:

Class diagram for concerts
Class diagram for concerts

Here’s a possible answer:

Class diagram for concerts with associations
Class diagram for concerts with associations
  • A band can perform at zero, one, or many concerts.

  • A single concert can include several bands (but at least one).

  • However, a single concert can only take place in one concert venue.

  • This venue can host zero, one, or many concerts (on different dates).

  • A concert venue must have one - and only one - address.

  • But a single address might have no concert venues or could have many.

Let’s Recap!

  • Model associations between classes on a diagram using lines to link them.

  • An association can be one of three types:

    • Many-to-many

    • One-to-many

    • One-to-one

  • Use multiplicity to specify these:  0..1  ,  1  ,  1..*  , etc.

  • An association can have attributes, which you indicate using an association class.

  • To indicate that a class is a component of another, define the association using composition.

There you have it! You have laid the foundations for your UML diagram. Now, you just need to refine it using UML language features.

Example of certificate of achievement
Example of certificate of achievement