View Full Version : Conventional Class Aggregation

16th February 2007, 05:55

I'm a self taught programmer coming from a procedural coding perspective (iso c) and I'm still developing my oop style skills.

I wonder, generally speaking, if I have a .ui derived class (qdesigner), should I use that class as the aggregate for other (non .ui) component (related) classes, or would practical convention consider otherwise?

Let me generalize this question... conventionally, is there a structured approach to determining how related classes might be aggregated "artistically"?


16th February 2007, 13:57
Aggregation can be best described as an "IS-PART-OF"-relation. That is a relation which does not apply to classes derived from .ui-generated classes, as those .ui-generated classes are not a part of your dialog, but a simple parent for inheritance.

A good example for aggregation would be a car with an engine and tires:

// engine is-part-of a car
class Engine

// tire is-part-of a car
class Tire

// a car is build from tires and an engine
class Car
Engine m_engine;
Tire* m_tires[4];

// and now inheritance:
// a Volkswagen is-a car
class Volkswagen : public Car

So, the basic difference between aggregation and inheritance boils down to:
1) Inheritance means you inherit something from one class to another (IS-KIND-OF or IS-A relationship)
2) Aggregation combines several simple parts to construct a more complex object (IS-PART-OF relationship)

16th February 2007, 14:21
Aggregation can be best described as...

Thank you Methedrine.

Simply reminding me again of the IS-A, IS-PART-OF thought process, along with the "option" having the related classes in a single source file, helped me to better structure my code.

As with all good instruction, your brief example demonstration was very illustrative.