• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

have a question about Has-A relationship

 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about Has-A relationship (object).
for example,

Is the above example "a Has-A relationship"?
Thank you.
 
Miki Muzsi
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, in this case Person has a shoe. And btw, for coding standards is prefered that the class starts with a capital .
And is-a relationship would be if for example you extend class Person (of Shoe)
e.g.
class Person {
Shoe shoe = new Shoe();
}
class Student extends Person {
...
}
In this case:
Student is-a Person
Person has-a Shoe
Student has-a Shoe (via inheritence!!!)
Hope it helps,
Miki
 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thank you.
What's the benefit of using "Has-A" relationship?
 
Miki Muzsi
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has-a and is-a relationship are used in object oriented programming. I would suggest to take a book on OOP or find something on the net. As a start you can have a look here.
Tha main idea is that is-a is used for inheritence, and has-a is used for composition. Both have their own strength; however many times has-a is prefered over is-a.
However for the exam you only need to know the basics and to recognize is-a and has-a constructs.
Good luck,
Miki
 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Miki Muzsi,
Thank you for providing me the information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic