• 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

when to use aggregation and when to use inheritance

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any cost related to use of aggregation and inheritance ???Which one is better to use and when should we use either of them??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"is a" versus "has a" relationship. A car has wheels. A car is a vehicle.

No decision should be made on "cost" -- but rather what makes the most sense for the model.
 
abhijeet kush
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we use inheritance then does it increases the size of subclass(all the methods of superclass are added to subclass )
 
Marshal
Posts: 79179
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abhijeet kush wrote:If we use inheritance then does it increases the size of subclass(all the methods of superclass are added to subclass )

Not at all. Whichever technique you use, the classes have the same number of methods: those you wrote and those inherited from superclasses. Each method is recorded once for each time it is written, so overridden methods are duplicated. So there is no need to worry about using too much memory.
 
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While using HAS A relation we will be using the same method as it was in original class so we ultimately end up creating a duplicate class,but if we are establishing IS A relation we can override the method of class we inherit..

This is how i think while coding and it helps me
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abhijeet kush wrote:If we use inheritance then does it increases the size of subclass(all the methods of superclass are added to subclass )


Who cares? This is the sort of thing that should not be part of the decision of how to model the data.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote: . . .This is the sort of thing that should not be part of the decision of how to model the data.

Even more so when it is probably wrong
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic