• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inheritance vs Aggregation

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,

Polymorphism can be acheived by two means:
1.Inheritance is-a relationship
2.Aggregation has-a relationship

Inheritance is achieved by extending the existing class using the extends clause and Aggregation is by declaring a object of a class as a member in another class.

I need some clarifications on when and where to use inheritance and aggregation.

Please provide me with some examples and explanations.

Thanks & Regards,
Prasath T
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prasath Thirumoorthy:
...Polymorphism can be acheived by two means:
1.Inheritance is-a relationship
2.Aggregation has-a relationship
...


Uh...

Originally posted by Prasath Thirumoorthy:
...I need some clarifications on when and where to use inheritance and aggregation...


In general, favor composition (has-a) over inheritance (is-a). If you have a need for polymorphism, then use inheritance. (But you're going to need to clarify exactly what polymorphism is before this makes sense.)
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an older article (from 1998), but the concepts are fundamental: Artima Developer - Composition versus Inheritance.
 
reply
    Bookmark Topic Watch Topic
  • New Topic