Review of Object Relationships
Understand the relationships between real-life objects.
We'll cover the following
Object relationship
In our daily lives, we encounter numerous recurring patterns, relationships, and hierarchies among objects. By exploring and understanding these, we can gain valuable insights into how real-life objects behave, ultimately enhancing our understanding of them.
For example, let’s say one day, we walk into a room and see a rectangular object with a flat surface surrounded by several four-legged objects with flat surfaces on top. We would easily identify the rectangular object as a table and the four-legged objects as chairs. Despite being unfamiliar with the room, we would intuitively comprehend that tables are designed for holding objects, and chairs are designed for seating. Furthermore, we would recognize that removing the table would deprive the chairs of a surface to accompany them.
It’s quite remarkable how we can instantly recognize the objects in the room, even if we’ve never seen them before. The reason behind this is our fundamental understanding of what furniture is and our ability to recognize that these objects represent that concept. We know that tables generally have a flat surface for holding items, and chairs are usually designed for seating. Furthermore, we comprehend that chairs are meant to be used with a table, and without it, they serve no real purpose. With this knowledge of furniture, we can easily make conclusions about these specific objects in the room.
Relationships between objects
In our everyday lives, we encounter numerous relationships between objects and have specific terms to describe them. For example, we could say that a library owns a book, a musician has a guitar, a basketball is necessary for a game, or a recipe requires certain ingredients. We can also understand that a car includes a steering wheel, and a human body contains a heart. These relationship types allow us to comprehend the connections between various objects and their significance in our daily lives.
In the world of programming, much like in real life, we encounter a plethora of recurring patterns, relationships, and hierarchies. These patterns that govern real-life objects can be applied to the objects we create in programming. Understanding these patterns in greater detail allows us to enhance code reusability and create more versatile classes.
In the previous chapter, we explored various concepts, including the use of loops and functions to perform tasks iteratively and the utilization of structs and classes to create objects of specific types. Building upon this foundation, the current chapter will primarily center around reviewing different relations from an object-oriented programming (OOP) perspective. Moreover, we’ll explore their practical application within C++ classes, further enhancing our understanding of their implementation in real-world scenarios.
Types of relationships
We’ll discuss five object relations:
- Composition
- Aggregation
- Association
- Inheritance
- Dependency
As a programmer using C++, we can effectively express the ideas of these object relations in code. In the upcoming lessons, we’ll explore them further through programming examples to gain a practical understanding.