In UML, composition is depicted as a filled diamond and a solid line. Aggregation is depicted as an open diamond and a solid line. The below image shows compostion, and then aggregation. The code below shows what the source code is likely to look like.

Image:AggregationAndComposition.png

class Car
{
  public:
    virtual ~Car() {delete itsCarb;}
  private:
    Carburetor* itsCarb
};
class Pond
{
  private:
    vector<Duck*> itsDucks;
};

Composition implies control for the lifetime of the object

Aggregation , the objects lifetime are independent of each other

 

Hosted by www.Geocities.ws

1