I have the following class cDrawObjectCreator:
class cDrawObjectCreator
{
public:
cDrawObjectCreator( cCompositeRoot *compositeObject ) { m_compositeRoo开发者_如何转开发t = compositeObject; }
~cDrawObjectCreator() {};
...
private:
cCompositeRoot *m_compositeRoot;
};
It is correct diagram?
or the following diagram is correct?
First one again. For the same reasons as in the previous Question.
Please read this, to see the difference between Compostion and Aggregation.
As a general rule, aggregation (hollow diamond) is a specialization of association, and composition (filled diamond) is a specialization of aggregation.
Remember the purpose of modeling is to facilitate communication so you would use different level of abstractions depending on the purpose and the stakeholders.
If you want to say that cMimicObjectCreator has an exclusive ownership of cCompositeRoot (that is, like a human / an animal body has a brain) then you would use composition (filled diamond). And if you want to say that cMimicObjectCreator has a cCompositeRoot (but not exclusively and that there are cases where the part class is not exist in the whole/container, like say...a boat with a GPS equipment) then you would use aggregation relationship.
To answer your original question, I think the first diagram is more appropriate. However remember also you can always use association relationship in place of composition or aggregation relationship if you want to be more "general".
精彩评论