开发者

Does the Derived class need diamond link?

开发者 https://www.devze.com 2023-01-07 06:39 出处:网络
If, for example, I have the following requirements: 1. Dog is an Animal 2. Zoo has Animal(s) Do I still need the 2nd diamond connector (the lower one) as shown here:

If, for example, I have the following requirements: 1. Dog is an Animal 2. Zoo has Animal(s) Do I still need the 2nd diamond connector (the lower one) as shown here:

Does the Derived class need diamond link?

开发者_如何学Python


The 2nd diamond connector is redundant. Here is some advice about UML class diagrams style: http://www.agilemodeling.com/style/classDiagram.htm


The 2nd diamond connector suggests that in addition to animals the Zoo also has specifically Dogs.


Hi before tackling UML use your common sense :)

Do you want to model that zoo have animals of different species ? Then you should not only put dogs but also cats and all other animals class that can exist in THIS zoo type (class) and just use one diamond connector.


  1. Don't use white diamond connector. Use either "composition" or "association". In your case, use "association". The author of "UML distilled" has following comments.

  2. The second aggregation is not necessary. However, you can change your model in this way:

    (1) Set the first aggregation's target role (at Animal side) "animals".

    (2) Delete the second aggregation.

    (3) Create another class DogZoo, generalize from Zoo.

    (4) Draw an aggregation from DogZoo to Dog, with the target role "dogs {redefines animals}"

Hope that helps.

0

精彩评论

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