• Post Reply Bookmark Topic Watch Topic
  • New Topic

Aggregation in Java?  RSS feed

 
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks yaar

Regards,
Narendranath
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!