• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Has-A Relationships

 
Saurabh Verma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I having problem in Has-A relationships concept.
What is the practical use of this?How can we use in normal code?

Thnaks.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Suppose that you have two classes, Car and Steering.

As we all know, all cars have a steering, so the following code illustrates the concept of the HAS-A relationship:



From the code above, and specifically in the Car class, you can see that the Car class has a reference to a Steering, so it is said that Car HAS-A Steering.

Did you get it ?
 
Saurabh Verma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vassili!!

But I still have some confusion.Now class Car has a reference variable of class Steering.What is the use of that reference variable?
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The use of it is as the use of any other object you use in any application ...
 
Saurabh Verma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!!
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anytime ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic