Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does is-a imply has-a ?

 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A { C c = new C(); }
class B extends A {}
1. B has-a C ?
class A { private C c = new C(); }
class B extends A {}
2. B has-a C ?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup.
If B inherits from A, and A has an inheritable member c of type C, then B inherits that member and, therefore, B "has a" C.
In the second case, however, the member is private so it is not inherited. Therefore, in that case, B doesn't have a C.
[ July 18, 2003: Message edited by: Corey McGlone ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Corey.
I am getting is-a and has-a confused with class diagrams. I was thinking is-a is the inheritance arrow and has-a is the aggregation symbol. I first saw the terms is-a and has-a in the UML User's Guide.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic