Last post Sep 21, 2013 02:47 PM by PatriceSc
Sep 21, 2013 02:32 PM|tahazubairahmed|LINK
I need to find pratical explaination of Composition in C#.
Composition is again specialize form of Aggregation. It is a strong type of Aggregation. Child object does not have their lifecycle and if parent object deletes all child objects will also be deleted.
Lets take an example, Houses and Room.
public class Room
public class House
Room r = new Room();
If we delete House class (Parent) how should child object destoy which Room
Sep 21, 2013 02:47 PM|PatriceSc|LINK
As you told "if parent object deletes all child objects will also be deleted" so I'm not sure to see what you mean with "how should child object destoy which Room" ??
The idea is just to use a type to build a more complex type. So here you create a Room type. Then you can create a House type that has Room(s). When you'll delete a House, its rooms will be deleted as a room doesn't exists without being part of a House.
Try perhaps to rephrase your question.