I can not distinguish the difference between aggregating and holding. What does it mean in terms of, let`s say, C++?
I suppose when the object of class A holds (or instantiates) objects of class B, it uses it to perform some functions by itself.
For example:
class A { int state; public: A(int s): state(s) {} int inc() { return state++; } }; class B { int app; string s; public: B(): app(0), s('') {} B(int A, const string& str): app(A), s(str) {} void f(int p); ~B() { app = 0; s = ''; } }; void B::f(int p) { A mA(p); app = mA.inc(); }
And the aggregation of object of class A would be like this:
class B{ A t; //... }
Please give me a link to a web-site or to a place in a book where I can find clear definitions in terms of OO language what exactly each kind of relationship between classes is.
Holding another class means that a class is associated with another class through a parent child relationship. For example a Path has a list of points. The Path is the parent of the List of Points which is the parent of the individual points.
Aggregating means taking different classes and putting them behind a interface so they appear as one class. For example a FileDialog will have several button class, a text input class, a listview/treeview class and so on. But to the rest of the system it just had methods to be activate, maybe assign a default filename, and retrieve the rest.
The fact it is comprised of all the other classes is immaterial to other classes using it as a filedialog.However it works by aggregating all the classes to perform the expected behavior.