Association

In this lesson, we'll learn about the relationship between two unrelated objects that is the association in C++.

We'll cover the following

In object-oriented programming, association is the relationship between the unrelated objects of the classes. Objects lifespan are not directly tied to each other like in composition and aggregation. To clearly understand the concept of the association we’ll take an example of student and teacher class.

Example

The teacher has a relationship with his students, but it’s not a part-of relationship as in composition. A teacher can add many students to a class, and a student can be registered in many courses. Neither of the objects(teacher and student) lifespan is tied to the other as any student can leave the class of specific teacher and similarly any teacher can change the course which he’s currently teaching. Let’s look at the implementation:

Get hands-on with 1400+ tech skills courses.