Thursday, April 24, 2008

Object oriented relations and its implementation in C++

Object oriented relations and its implementation in C++:

Has a - aka composition
  • Is implemented with member variables. If the member is heap allocated then the implementation happens with pointers. In this case the pointee object has to be destroyed when the aggregator is destroyed.
Uses a - aka aggregation
  • Is implemented with member variables of type "reference (&)". When the aggregator is destroyed the aggregates are not destroyed.
Can use a - aka weak aggregation
  • Is implemented with member variables of type "pointer (*)" but the pointer is initialized "empty" (with NULL) and set later to point to a certain object. When the aggregator is destroyed the aggregates are not destroyed.
Is a - aka inheritance
  • Public inheritance (all public members of the base class are accessible by a user of the derived class).
  • Private inheritance (all public members of the base class are hidden from the user of the derived class). This kind of inheritance is used for providing a "new" interface. It is also known as "class Derived is implemented in terms of class Base".