‫Welcome back.
‫In this video we are going to talk about has a relationship because so far what we have seen in inheritance
‫is an is a relationship.
‫So here, for example, I'm going to get rid of the SEALs here from last video.
‫So a car or a BMW better set?
‫A BMW is a car.
‫So it's an is a relationship between BMW and car.
‫The same for Audi?
‫An Audi is a car, an MX three is a BMW.
‫So that's pretty much the general idea of inheritance.
‫But there is also something called an has a relationship.
‫So let's say we would like to have an additional information set for our car in general for every car
‫there is.
‫So what we can do there for is to create an additional class and I'm going to call this class car info
‫or actually let's go ahead and create that maybe even car ID info.
‫So in order to identify every single car, let's create a new class and call it one car ID info.
‫So this class here has a inheritance or relationship, so pretty much a BMW has a car ID info or a car
‫has a car ID info.
‫So in here I just want to have some properties.
‫For example, an integer called ID num.
‫So this one will be initialized with zero and otherwise this is just going to be the ID, which is a
‫unique identifier, not a number.
‫So it's pretty much every car has this number and it's unique.
‫So car one has the ID of zero, the second car has the idea of one and so forth.
‫And also every car should have an owner.
‫So public string owner and actually I'm going to use a property as well.
‫So prop string owner and here also get and set and if it doesn't have an owner, then the standard statement
‫should be no owner.
‫So let's say the car was just produced.
‫Of course, you could argue that this car is still owned by the company that produced it, let's say
‫by a BMW or by Audi or by any other car producer, and otherwise it has an owner.
‫So in that case, let's say it has no owner, but otherwise it has an owner.
‫So this car ID info is something that I can create an instance of in my car class and then I can use
‫it in any other of the driving classes as well.
‫So let's go ahead and do that.
‫Let's create in here a has a relationship has a relationship which means a car has a protected car ID
‫info and I'm going to call that one car ID info, which is a new car ID info.
‫And now in my car I'd InfoQ I can simply set things so we could go ahead and create setters in here
‫and all of those kind of things.
‫But I'm just going to use that right in here because the beauty about having properties is that I can
‫actually access them in here so I can create a method called set car ID info.
‫So that will do is it will simply set the car ID ID that one here dot id num two id num.
‫And now you're wondering where is this ID name coming from, this second one here?
‫Well, it's an integer that I'm going to deliver whenever I'm setting.
‫So this is going to be a property here.
‫And another one that I need is the owner.
‫So string owner.
‫So when I set the car ID info, I want to have these two information and this information.
‫And in here I also can say car ID info is going to be here.
‫It's the owner is going to be the owner, but here actually not capitalized if possible.
‫So we have the owner and it will be the car owner whenever we use the set car ID info method.
‫So let's go ahead and get the car ID info as well by creating a new method public void, get car ID
‫info and that one will simply write something onto the console.
‫Something like the car has the ID of and here I'm going to use zero and is owned by and here I'm going
‫to use the one.
‫So here I'm going to say car ID info dot ID number and car ID info dot owner.
‫So what that allows me to do is to adjust the card info for every single car that I have, no matter
‫if it's just a car, if it's a BMW, if it's an Audi three or whatever.
‫Because this class has now a has a relationship here.
‫So we simply can go ahead into the program class and in here we can add some information.
‫So let's say we want to add some info to our BMW and oh, is that three?
‫So let's go ahead and do that here.
‫BMW Z three is going to get a car ID info, which is let's say this one has the idea of one, two,
‫three, four and the owner is going to be Dennis on Utah.
‫And now there is the Audi a three and this one is going to get a car ID info of one, two, three or
‫five and the owner is going to be Frank White.
‫And now we can go ahead and get those IDs, get car ID info for the BMW and also for the Audi three,
‫get car ID info.
‫So now if you call that or if we run that code, we will see that the additional info is available at
‫our car.
‫So that's a way that you can simply add information to an object.
‫So you can see the car has the idea of one, two, three, four, and it's owned by Dennis Panetta and
‫the car has the ID of one, two, three, five and is owned by Frank White.
‫All right.
‫So that's generally how you can go ahead and add information.
‫So that's an aggregator for our car.
‫And it's it has a relationship way of approaching things.
‫Great.
‫So that's pretty much it about has a relationships.
‫So see you in the next video.