Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Has-a relationship

 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A {}
class B extends A {}
class C { B b; }

C has-a B, but my doubt is if C has-a A is also true, because B extends A

Thanks
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have guessed that C HAS-A A, as B IS-A.
But the reference is actual to a class of type B, therefore I would say C dosnt HAVE-A A.

But that is just my guess, would like to know what others think
[ March 20, 2007: Message edited by: Gavin Tranter ]
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. C has A through B, would be more proper.

There is difference in saying "C has A" and "C has A through B."

1)C has A: Here A's methods will work on its data.

2)"C has A through B." : when Method overriding takes place, "B method may include its own data too".

Hope its clear.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic