hey in case of aggregation, how you initialize worker object in class scope. you have to initialize in somewhere method. because as by u did, this behavior matches to composition. if manager obj destroy so worker will also destroy bcoz worker behaves like manager data item. please if i am wrong. correct me through khayamabdulnasir@gmail.com
Above article is really a good at building concept using real life example. Also I've found another good article explaining difference between Composition and Aggregation;
Thanks for the article.
This is regarding the Composition section of your Article. In composition relationship, "Lifetime of Part depends on the Lifetime of Whole". In your example, "Project" and "Manager" is not developing a part-whole relation. Your are passing the the "Manager" object in "Project"'s constructor. You are creating the "Manager" object outside the "Project". So, your "Manager" can still survive even "Project" is destroyed.As far as my concept goes, I agree this is a case of "Aggregation" and also might result to a dependency but not a Composition. Please correct me if I am wrong.
Don't think Manager as Physical Entity..consider it as a logical entity..An Employee is Manager only when that Employee is assigned a Project(then employee becomes Manager),and when project is complete(destroyed) then employee's Role as a manager may be revoked.
I spent entire weekend reading all your articles. Gotta say, I loved them. It was time well spent. I spent all my Monday early morning voting, categorizing and bookmarking my favourite ones. Loved the content, became fan of presentation style.
Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.
That's definitely more simplified. I have not see the Wheel class. But the wheel class should also refer the car object so that there is tight bonding or else i can attach the wheel to trucks also which probably is more of aggregation.
Yep, thats exactly the difference (Wheels and engine in my example don't reference the car, nethertheless I say this is composition). I wrote this with C++ in mind, so engine and wheels cannot extend their lifecycle beyond that of the car. They also cannot be moved to another car, only copied.
I agree what you are saying the child reference to parent is not needed and the most important thing is that childs object life time is depedent on parent.