• Post Reply Bookmark Topic Watch Topic
  • New Topic

HAS-A relationship  RSS feed

 
Persian Sama
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
from the code below


I need to know if the tie method invoked in the horse class is overridden, otherwise why we have the same tie signature ??
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isn't overriding, because the Halter class doesn't extend the Horse class. What that is is "delegation" - the Horse object delegates the action to the Halter object it contains.

Because of this, it isn't essential that the signature (or even the name) is the same. It would work just the same if it wasn't. But it makes sense to use the same signature if the method is doing exactly the same thing.
 
Persian Sama
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi MB,
i was just confused because of the signature form, so the tie method in the Horse class is it a different method from that on the Halter class ?
Thank you,
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right, yes. The only connection is in the mind of the programmer - as far as the compiler is concerned they are completely different.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!