Registered: Jul, 2006
Re: Aggregation , Association and composition
Posted: Jul 18, 2006 3:52 AM
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.
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.
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)
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.