开发者

UML Do you still show composition/aggregate objects as member variables?

开发者 https://www.devze.com 2023-03-27 17:30 出处:网络
If I had a class Airplane and a class Win开发者_运维问答g, if there was a composition relationship between the two, does Airplane have a member variable of type Wing in the class diagram, shown in the

If I had a class Airplane and a class Win开发者_运维问答g, if there was a composition relationship between the two, does Airplane have a member variable of type Wing in the class diagram, shown in the Airplane box?


ASCII art!

+-------------+ 1        1..* +----------+
|  Airplane   |<*>------------|   Wing   |
+-------------+               +----------+

where <*> represents a filled diamond, indicating composition. I used multiplicity 1..*, since it's possible to have aircraft that are essentially a single wing (such as the B-2), and although nobody builds them anymore AFAIK, you have biplanes (2 or 3 wings, depending on how you're counting), triplanes, etc.


No. Compositions and aggregations are kinds of associations and are shown like associations, i.e., with lines between classes (with solid and hollow diamonds, respectively, on the containing side). As a general rule, if you have an attribute whose type is a class, your model is wrong.

Implementation is a completely separate matter from analysis/design. You may implement associations in a variety of ways, including using member variables e.g. in C++.


I'm not sure at 100%, but as far I remember no. Is just implicit that u will'have a variable of type Wing.


No, it doesn't. But that doesn't mean that you can't have an attribute that is of class type. You just can't have both. It's a choice about what you want to emphasise.

0

精彩评论

暂无评论...
验证码 换一张
取 消