Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Aggregation in Java?

 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Java classes can be created by Inheritence/ Aggregation.I know about Inheritence. Can anyone tell me about Aggregation? And how the new classes are created using Aggregation?

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

In short you combine a number of objects into an object. As in, a car
consists of four wheels, 2 doors ect.



My jag now consists of wheels and doors. An aggregation is alot like an
association, the only difference is, that associations change more
frequently.

/Svend Rost
 
Naren Chivukula
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks yaar

Regards,
Narendranath
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Composition is sometimes viewed as an alternative to inheritance, usually with the advice "prefer composition". Rather than extend HashMap to add functionality you could make a class that has a hidden HashMap, passes all the HashMap methods through to the hidden map and implements a few additional methods. Some of the reasons are kinda theoretical but this approach does avoid some real problems in more complex applications

For all the gorey details, see Why Extends is Evil and bear in mind Holub's point of view is quite controversial in some circles.
[ June 02, 2005: Message edited by: Stan James ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I think a better example of aggregation (or composition) would be to show a Car class. Perhaps something like this:

In the above example, Wheel and Door are classes themselves. I leave out the details for those two since the important issue here is that the Car class "aggregates" Wheel and Door objects. This is the key idea behind aggregation. Svend's example is similar but shows how to USE a Car class that presumably has WheelGroup and DoorGroup members. Either way, the idea of aggregation is that one class contains members that are themselves instances of other classes.

Layne
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic