Composition: “has-a” relationship
What is Composition? Imagine you have a toy car. This toy car has different parts: wheels, a body, an engine, and so on. The toy car has wheels, it has a body, and it has an engine. This is exactly what composition is in programming. It means that one object is made up of other objects. We can use classes to represent this “has-a” relationship. Let’s look at how this works with a simple example. Example: Building a Toy Car Step 1: Creating the Parts First, let’s create the different parts of our toy car. We will create a class…
