The type of relationship shared between Order and OrderItem classes is known as Composition relationship.
Inheritance
Inheritance is a big topic in itself to talk about. Here, we are not talking about the different types of inheritance and how it is implemented in code. We will only be talking about inheritance as a relationship.
Inheritance is sometimes referred as
"is a" relationship. In this type of relationship, one class inherits the members of another class. The inherited class is known as the base class, whereas the inheriting class is known as the derived class. As the derived class has the members of base class, it can be said that the derived class
is a sub-type of the base class. The derived class may or may not have members other than the inherited ones.
Assume that our application is running quite well in the market. Seeing that, the product owner now wants to add a new feature in the application that would monitor the type of products having a high demand. From the new requirement, it is quite clear that we will have to create sub-types of our Product class. These sub-types will represent the specialized product categories in the real world, as shown in the image below.
The classes MusicAlbum and Book, as shown in the above image have some properties of their own. And because they inherit from the Product class, they inherit its properties as well. So it can be said that MusicAlbum is a type of Product and so is the Book.
I hope this helps you get a basic understanding about the object relationships. It’s always great to have feedback from the readers. Your valuable feedback, question, or comments about this article are always welcome.