How to model 1 to 0..* aggregation in UML

c++ uml enterprise-architect

135 观看


423 作者的声誉

I would like to model a Hal_device_factory class with container, that collects pointers to interfaces of type IHal_subfactory.

I made such class diagram in Enterprise Architect:

enter image description here

Then I generated source code for this diagram, this is what i've got:

std::set<IHal_subfactory>  *m_IHal_subfactory;

However I expected something like that :

std::set<IHal_subfactory*>  m_IHal_subfactory;

So my question is what I've done wrong ? Model is wrong or what ?

作者: wiesniak 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


3010 作者的声誉

I think, your model is correct.

If you want to have an instance of your set instead of a pointer to it:

you should set your Aggregation containment to Value instead of Reference:

In your Aggregation Relationship -> go to Properties -> Role(s) -> in Source section -> in the list at Advanced section -> set Containment to Value.

作者: Gholamali-Irani 发布者: 28.12.2017 01:11