Object Relationships
As mentioned previously, classes interact with one another to function in an objectoriented program.
There are four primary relationships between classes:
- Association (“uses-a”)
- Aggregation (“has-a”)
- Composition (“owns-a”)
- Inheritance (“is-a”)
Credits: the examples here come from a PTS reviewer made by Cai Benjamin Reyes and Diane Panganiban!
For practice, why not try coding the diagrams here into java code?
Association (“Uses-a”)
Section titled “Association (“Uses-a”)”Association describes a relationship where one class uses another class, but both can exist independently.
Neither object owns the other as they simply work together.
Bidirectional Association
Section titled “Bidirectional Association”A bidirectional association means both classes know about each other.
In the example below, the Plane knows which Airport it is currently in, while the Airport keeps track of the planes currently at the airport.

Note: The airport is not responsible for creating or owning the planes. It simply keeps a record of which planes are currently there.
Since both classes are aware of each other, the relationship is bidirectional.
Unidirectional Association
Section titled “Unidirectional Association”Sometimes only one class needs to know about the other.
In this example, the Plane knows about the Airport, but the Airport has no reference to the Plane.

This is called a unidirectional association.
Key Idea: Association simply means one class uses another class. Neither class owns the other, and both can exist independently.
Aggregation
Section titled “Aggregation”Aggregation describes a has-a relationship.
The parent class contains one or more child objects, but the child objects can still exist without the parent.
Think of it as a weak ownership relationship.
Example: A playlist has a list of songs.

Note that deleting the playlist does not delete the songs, they can still exist in another playlist.
Key Idea: The child object has its own independent lifecycle.
If the parent disappears, the child can continue to exist.
Composition
Section titled “Composition”Composition is a stronger version of aggregation.
It also represents a has-a relationship, but this time the child object cannot exist without the parent.
Example: A company owns teams

Notice that the Company creates and manages its Team objects.
If the company is deleted, its teams disappear as well! (ded)
Key Idea: The parent completely owns the child. Destroying the parent also destroys the child.
Aggregation + Composition
Section titled “Aggregation + Composition”The sample below shows a combination of aggregation and composition.

A team is a part-of a company, and a team has-an employee.
Inheritance
Section titled “Inheritance”Lastly, Inheritance describes an is-a relationship.
A child class inherits the attributes and methods of its parent class (super class).

A Student is a Person.
A Professor is also a Person.
Both Student and Professor inherit the common characteristics of Person.
In Java, inheritance is written using the extends keyword.
class Person {
}
class Student extends Person { // You can apply polymorphism here!}
class Professor extends Person { // You can apply polymorphism here!}
// Wow advance study?!Key Idea: Inheritance allows multiple classes to share common attributes and methods without rewriting code.
UML Symbols
Section titled “UML Symbols”Each relationship has its own UML notation.
| Relationship | UML Symbol | Meaning |
|---|---|---|
| Association | Line (with or without arrowheads) | Uses-a |
| Aggregation | Hollow diamond ◇ | Has-a (weak ownership) |
| Composition | Filled diamond ◆ | Has-a (strong ownership) |
| Inheritance | Hollow triangle △ | Is-a |
Cheatsheet by Khalil Stemmler
Multiplicity
Section titled “Multiplicity”Some UML diagrams include numbers beside the relationship lines.
For example:
1-> Exactly one object0..1-> Zero or one object0..*-> Zero or more objects1..*-> One or more objects
In the Playlist example, 1..* indicates that a playlist contains one or more songs.
These numbers describe how many objects participate in the relationship.
Tech tip: A quick way to remember them is:
- Association: “I use it.”
- Aggregation: “I have it.”
- Composition: “I own it.”
- Inheritance: “I am it.”
YOU’RE IT!!! NOW GO ACE THAT EXAM