As far as my understanding for composition, the children cannot exist without the parent. But my instructor is suggesting that the following example is an aggregation, I just want another opinion.
class ItemForKids { }
class ItemForMen { }
class ItemForWomen { }
class PageContent {
private:
ItemForKids* itemForKids = NULL;
ItemForMen* itemForMen = NULL;
ItemForWomen* itemForWomen = NULL;
public:
PageContent() {
this->itemForKids = new ItemForKids();
this->itemForMen = new ItemForMen();
this->itemForWomen = new ItemForWomen();
}
~PageContent() {
delete this->itemForKids;
delete this->itemForMen;
delete this->itemForWomen;
}
}
2 Questions:
- Is above example aggregation or is it composition?
- My instructor suggests that if we change the pointers to regular variable then we don't need to initialize the object in constructor and then it will become composition, is this true?