The Artima Developer Community
Sponsored Link

Design Forum
Aggregation , Association and composition

18 replies on 2 pages. Most recent reply: Jan 13, 2011 3:38 AM by Olalekan Quadri

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 18 replies on 2 pages [ 1 2 | » ]
Leela

Posts: 16
Nickname: leee
Registered: Sep, 2003

Aggregation , Association and composition Posted: Dec 9, 2003 1:38 AM
Reply to this message Reply
Advertisement
Hi,

i am confused abt the difference between obj aggregation, association and composition. i wanted to know the theoritical difference as well as how it would represent itself in code(in C++ or JAVA).

Thanks,
Leela


prabhu

Posts: 2
Nickname: pabbu
Registered: Dec, 2003

Re: Aggregation , Association and composition Posted: Dec 30, 2003 7:31 AM
Reply to this message Reply
Hi Leela,

Association-- It means how objects are related for eample you and your father how ur associated means as a daughter right..?

Aggregation ---It means for example one Colleage is build up of Depatments and again departements contains classes right here school is aggregation of departements and again departement is aggregation of classes,here u can perfect aggregation of things if u delete the main object called school all associated departements and classes will get delete.

Compostion--It means how objects are composed of means in other words it is tightly bound aggregation here even u will not have access to delete child objects which are nested in parent objects.

regards
Prabhu

Ali Aghareza

Posts: 17
Nickname: aghareza
Registered: Aug, 2003

Re: Aggregation , Association and composition Posted: Dec 30, 2003 9:31 AM
Reply to this message Reply
> Hi,
>
> i am confused abt the difference between obj aggregation,
> association and composition. i wanted to know the
> theoritical difference as well as how it would represent
> itself in code(in C++ or JAVA).
>
> Thanks,
> Leela



Check out http://ootips.org/uml-hasa.html

H. E. Balder

Posts: 1
Nickname: hebalder
Registered: Jun, 2003

Re: Aggregation , Association and composition Posted: Dec 31, 2003 2:26 AM
Reply to this message Reply
Hello prabhu,

do you have interchanged your explanations for aggregation and composition ?

cu
Hugo

Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: Aggregation , Association and composition Posted: Feb 24, 2004 5:49 AM
Reply to this message Reply
pls don't inser confuse here....

Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.

[Example:]

|A|----------->|B|

class A
{
private:
B* itsB;
};
Aggregation [...] is the typical whole/part relationship. This is exactly the same as an association with the exception that instances cannot have cyclic aggregation relationships (i.e. a part cannot contain its whole).
[Example:]

|Node|<>-------->|Node|

class Node
{
private:
vector<Node*> itsNodes;
};
The fact that this is aggregation means that the instances of Node cannot form a cycle. Thus, this is a Tree of Nodes not a graph of Nodes.
Composition [...] is exactly like Aggregation except that the lifetime of the 'part' is controlled by the 'whole'. This control may be direct or transitive. That is, the 'whole' may take direct responsibility for creating or destroying the 'part', or it may accept an already created part, and later pass it on to some other whole that assumes responsibility for it.

[Example:]

|Car|<#>-------->|Carburetor|

class Car
{
public:
virtual ~Car() {delete itsCarb;}
private:
Carburetor* itsCarb
};

ashok

Posts: 1
Nickname: ashokms
Registered: May, 2005

Re: Aggregation , Association and composition Posted: May 19, 2005 2:38 PM
Reply to this message Reply
In breif ...
Association is nothing but a Relation between any two objects.

if u Take a Real world instance a vehicle with a horn..

a vehicle can work with a horn and vice versa.(this is the case for aggregation), which shows has a Relation between vehicle and horn

For Composition....

a vehicle with Engine ....... without engine a vehicle is useless and vice versa, which show must relation

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Aggregation , Association and composition Posted: Jun 5, 2005 3:19 AM
Reply to this message Reply
responding to Leela

> i am confused abt the difference between obj aggregation,
> association and composition. i wanted to know the
> theoritical difference as well as how it would represent
> itself in code(in C++ or JAVA).

First theory and let me know if you dont get it.

Association:
Literal meaing of association means. Being associated with each other means I know you, or you know me rught??

Whenever two objects communicate with each other its association relationship.

Association is of different types. Importantnly of three types.
1. I know u as well as so many other people as well. Same for you. You also know so many people.

This kind of relationship is depicted as simple Association in UML.

This is always characterised by "has a" relationship. Like I have your reference. You have mine reference. Both or none.

2. I am not complete without you. You make me complete. Example a music system consists of sound box, CD player, graphic equalizer etc.

So in other words we may say, a music system is aggregation of CD player, casette player, graphics equalizer, sound box etc.

Or music system object has aggregation relationship with each of the things mentioned above.

3. I am not complete without you. And you dont exist outside me.

Example could be a tree?

Branches, leaves, fruits dont exists outside it? If tree dies everything dies.

This is strongest form of association and called composition relationship.

Another examples could be relationship between a house and its rooms. Rooms dont exist outside a house? Same room cannot be shared across two houses? And all the rooms persishes if the house collapses.

regards,

------------
Shashank D. Jha
iCMG
e-mail : shashank@icmgworld.com
Phone : +91-80-98451 87302

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Aggregation , Association and composition Posted: Jun 6, 2005 9:15 AM
Reply to this message Reply
responding to Viswanatha


Can you provide reference to from where you got definition of composition ?

> the 'whole' may take direct responsibility for creating or
> destroying the 'part', or it may accept an already created
> part, and later pass it on to some other whole that
> assumes responsibility for it.

This may be helpful.

------------
Shashank D. Jha
iCMG
e-mail : shashank@icmgworld.com
Phone : +91-80-98451 87302

Balachandar

Posts: 1
Nickname: chandarb
Registered: Jun, 2005

Re: Aggregation , Association and composition Posted: Jun 19, 2005 7:45 AM
Reply to this message Reply
Keeping it Simple,
Aggregation or Composition depends up on life time of the child object.
If the child object cannot exist beyond the lifetime of its parent then the relationship is composite(Strong relationship)
If the child object can exist beyond the lifetime of its parent, then the relationship is aggregtion.However, at a particular moment the child object can be controlled only by a single parent(ie. Unshared), and it is the responsibility of the parent object to transfer the control of the child object to some other instance while its destruction.

a k

Posts: 1
Nickname: amanushya
Registered: Nov, 2005

Re: Aggregation , Association and composition Posted: Nov 19, 2005 2:03 PM
Reply to this message Reply
> Hi,
>
> i am confused abt the difference between obj aggregation,
> association and composition. i wanted to know the
> theoritical difference as well as how it would represent
> itself in code(in C++ or JAVA).
>
> Thanks,
> Leela

Hi,

The following qualifier in prev reply is only applicable for Composition relationship.
"However, at a particular moment the child object can be controlled only by a single parent(ie. Unshared), and it is the responsibility of the parent object to transfer the control of the child object to some other instance while its destruction."
In Composition, the participant (one whose instant is held by the composite) cannot be a child to another parent. In aggregation that is not the case.

Amanushya

shameer ali

Posts: 1
Nickname: progmatic
Registered: Apr, 2006

Re: Aggregation , Association and composition Posted: Apr 18, 2006 3:43 PM
Reply to this message Reply
> > Hi,
> >
> > i am confused abt the difference between obj
> aggregation,
> > association and composition. i wanted to know the
> > theoritical difference as well as how it would
> represent
> > itself in code(in C++ or JAVA).
> >
> > Thanks,
> > Leela
>
> Hi,
>
> The following qualifier in prev reply is only applicable
> for Composition relationship.
> "However, at a particular moment the child object can be
> controlled only by a single parent(ie. Unshared), and it
> is the responsibility of the parent object to transfer the
> control of the child object to some other instance while
> its destruction."
> In Composition, the participant (one whose instant is held
> by the composite) cannot be a child to another parent. In
> aggregation that is not the case.
>
> Amanushya

hi,

let me explain in my way.

We have only one relation between objects. that is called Association. Both aggregation and association are specilised form Association. again we can say composition is a specilised for aggregation.

so if there is any type of relation between two object there is association. now it can be aggregation or composition .

Consider a circle and points that make up the circle. circle is made up of points and if we destroy circle there is no points also.-this is composition

Consider an online order that contains different products.even if we destroy the order the products will be there as independent..and these product may be part of something else too...this is aggregation

Zaid Omar

Posts: 1
Nickname: zaid
Registered: Jul, 2006

Re: Aggregation , Association and composition Posted: Jul 18, 2006 6:52 AM
Reply to this message Reply
Life is simple, lets not complicate it.

Since most people in this forum are Computer Prgrammers, I would find it much easier to explain it like that.

Accosiation:
1. Create a folder called "Links"
2. create a shortcut inside this folder and link it to www.yahoo.com
3. create another shortcut instide this folder and link it to www.google.com
4. Ask your friend to do the same on another machine using same links (www.yahoo.com and www.google.com)
5. Delete the "Links" folder, and open your browser to check if www.yahoo.com and www.google.com still exist or not ;)

Briefly, Association is a relationship where all the objects have different lifecycles. There is no owner.



Composition:
1. Open a new Document name it as test.txt
2. Write this sentence in iside this document "This is a composition".
3. Save the document.
4. Now, delete this document.

This is what is called composition, you can't move the sentence "This is a composition" from the document because its lifecycle is linked to the parent (the document)

Aggregation:
1. Create a file called file.txt
2. make a simple application to open the file.txt (rw), but don't program it close the connection.
3. Run an instance of this application (it should work ok and can open the file for rw)
4. Keep the first instance, and run another instance of this application (In theory it should complain that it can't open the file in rw mode because it is already used by other application).
5. Close the 2 instances (make sure you close the connection).

From the above application, we knew that the Application and the file has a separate lifecycles, however this file can be opened only by one application simuletanously (there is only one parent at the same time, however, this parent can move the child to another parent or can make it orphan).

Hope this explanation gave you a bit more understanding.

Zaid Omar

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Aggregation , Association and composition Posted: Jul 20, 2006 9:53 AM
Reply to this message Reply
> Aggregation:
> 1. Create a file called file.txt
> 2. make a simple application to open the file.txt (rw),
> but don't program it close the connection.
> 3. Run an instance of this application (it should work ok
> and can open the file for rw)
> 4. Keep the first instance, and run another instance of
> this application (In theory it should complain that it
> can't open the file in rw mode because it is already used
> by other application).
> 5. Close the 2 instances (make sure you close the
> connection).
>
> From the above application, we knew that the Application
> and the file has a separate lifecycles, however this file
> can be opened only by one application simuletanously
> (there is only one parent at the same time, however, this
> parent can move the child to another parent or can make it
> orphan).

Is this composition or aggregation?

Rajasekar Muthusamy

Posts: 1
Nickname: rajsekarm
Registered: Nov, 2007

Re: Aggregation , Association and composition Posted: Nov 5, 2007 1:09 PM
Reply to this message Reply
Whether you guys explain me Composition and Aggregation are part of Association?

Alek Or

Posts: 3
Nickname: alek
Registered: Jan, 2008

Re: Aggregation , Association and composition Posted: Jan 27, 2008 4:17 PM
Reply to this message Reply
No. Aggregation and composition are kind of association.

Flat View: This topic has 18 replies on 2 pages [ 1  2 | » ]
Topic: Document for SRS Previous Topic   Next Topic Topic: Design for performance


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us