Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

" has a " relationship

 
Hung Chang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone explain to me what exactly is "has a" relationship..
thanx in advance
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "is a" relationship, as I assume you know, is inheritance, when one class extends another. Say you have a class "Plane" and another class "CommercialAirliner". A commercial airliner "is a" plane, therefore it would extend class Plane.
The "has a" relationship is what is called "aggregation". If you design a class called "Engine", and then design a class called "Car". A car "has a" engine. Therefore it would not extend engine, because a car is not an engine. It would therefore include an object of type Engine as one of its instance members.
Hope that's clear.
------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic