I have a question I would like clearing up for me. There seems to be so many terms for 'composition' (i.e. aggregation is another) and I get confused between them.
What is meant precisely by 'composition' and/or 'aggregation'? Here are two different examples. Is it A or B? Or both? Or neither?
I have a class Car. And I produce a class SportsCar which has Car as a public member, like so:
Therefore SportsCar is a composite. Is this right? Or is it the slightly more sophisticated example B, below:
My Car class now has a method for returning the number of wheels, like so:
Now I could build my SportsCar class so that it inherits from Car. However, I chose not to, but instead I do the following:
int Car::NumOfWheels() const;
Notice I has placed the Car object as a private member & reproduced its method(s) explicitly in SportsCar public. The implementation of SportsCar::NumOfWheels can be just a pass through to pCar, like so:
int NumOfWheels() const;
Is this what is meant by composition?
int SportsCar::NumOfWheels() const
I ask this question because I often hear that 'VB doesn't support inheritance, but supports aggregation instead.' Example B seems a way [albeit a laborious one] of replicating some features of inheritance.