aspose file tools*
The moose likes Beginning Java and the fly likes aggregation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "aggregation" Watch "aggregation" New topic
Author

aggregation

Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Hi, havent been on this site for a while.
Could someone please explain aggregation to me. I don't understand it!!!???!!
Ive been looing through all my books and still has not sunk in. Whats a basic definition for it and what could be a good example for it.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
well,
i don't know if this pertains to this forum(as it seems general question to me applicable to C++/C# any object oriented thing) but i'd try to provide u the answer...
aggregation as per the online
Merriam Dictionary,
1 : a group, body, or mass composed of many distinct parts or individuals
2 a : the collecting of units or parts into a mass or whole b : the condition of being so collected
i would say aggregation means "is consist of" term that specifies that "something is consist of something because else the first something doesn't exist " (sorry for little confusing statement. it would sound like recursion)
e.g.
1. CAR is an aggregation of engine, tires,seats etc...
(engine is consist of these things. it can't be there w/o those things. can u think of a car w/o engine??)
engine can be again defined as aggregation of brakes, battery, timing belt u know etc...
2. world is an aggregation of people in it
(world consist of people. if there is no person on earth then its probably just a planet and no one would be refering it to as 'world', right?)

3. JAR file is an aggregation of classes and other possible resources
4. computer is an aggregation of,
CPU, monitor,key board, mouse etc
what i 've observed in most cases is- the top object, which is the aggregation of set of certain other thing, is 'logical' not 'physical'.
CAR i would say is just a word. it becomes a real object when we have put together engine, seats,stearing etc...by definition of a CAR we just percieve that it has to have certain properties like tires, engine etc
hope this helps u.
regards
maulin
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
How about this...
Inheritance uses IS-A relationships, for instance: Dog IS-A Canine and Canine IS-A Animal
Aggregation uses HAS-A relationships, for instance: Dog HAS-A collar Car HAS-A Engine.
In Java, aggregation means one class that has, as some of its instance variables, instances of other classes, for example:
class Dog {
Collar c = new Collar( );
}
This is aggregation, Dog HAS-A Collar.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
As a pre-emptive measure, the question asked for a 'basic' explanation and example - sticklers might say this is an over-simplification but I'm sticking to my 'this is a good basic 'answer / example' ' guns.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
In this context, some programmers may use the word composition (for the 'has a' relationship). This word might be more comfortable for some.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
As a pre-emptive measure, the question asked for a 'basic' explanation and example - sticklers might say this is an over-simplification but I'm sticking to my 'this is a good basic 'answer / example' ' guns.
 
Don't get me started about those stupid light bulbs.
 
subject: aggregation