Reputation: 532
I have the following code:
class D;
class E;
#include "B.h"
#include "C.h"
#include "F.h"
#include "G.h"
#include <vector>
class A: public G {
B b;
std::vector<C> cs;
D* d;
std::vector<E*> es;
std::vector<F*> fs;
public:
A() { fs.push_back(new F); fs.push_back(new F); }
};
int main() {}
in Bouml i generated class diagram from this code:
I thought that (https://softwareengineering.stackexchange.com/questions/255973/c-association-aggregation-and-composition) relationship between A and F had to produce an aggregation relationship but it produced an association relationship. How can i establish an aggregation relationship?
Upvotes: 2
Views: 1008
Reputation: 32594
It is very difficult for a reverse to distinguish an association and an aggregation. In Bouml the C++ reverse always produces an association when a type is referenced by a pointer even through a template (case for d, es and sf), else a composition (case for b and cs)
Bouml manages C++11 since the 5.1 distributed April 26th 2012
Upvotes: 1
Reputation: 238461
This is how the page that you linked describes association and aggregation:
Association: Foo has a pointer to Bar object as a data member, without managing the Bar object -> Foo knows about Bar
Aggregation: Foo has a pointer to Bar object and manages the lifetime of that object -> Foo contains a Bar, but can also exist without it.
So, their difference is that in case of aggregation, A
(in your case) manages the lifetime of the pointed object(s). Currently, A
does not manage the lifetime of the F
objects. Therefore the relationship is indeed association. The relationship is clearly identical to the E
type.
If A
's destructor would destroy all the pointed objects, then A
would be managing the lifetime of the objects and the mapping would be considered aggregation according to the given definition.
I don't have experience with Bouml, but I highly doubt that it would be able figure out what the destructor does. My guess is that it deduces the diagram based on the types of the members and what it knows about existing, standard classes. A pointer type does not signify anything about ownership, so based on the type alone, it's impossible to distinguish association and aggregation.
However, std::unique_ptr
does signify ownership clearly. If the vector contained them, then aggregation relationship could be trivially deduced from the type. As I don't have experience with Bouml, I don't know if it does such deduction.
Upvotes: 3