简体   繁体   中英

Modelling UML Class Diagram with a stack variable

Say I have Class A, and inside that I have a Class B.

Inside Class A, I also have a stack of Class B's.

How do I exactly write the notation out in a UML Diagram for Class A, and what is the relationship between Class A and B?

Class A may share a composition relationship with class B, whereas A is 1 to many B. Usually you represent this by connecting the two classes with an arrow in UML, having "1" in A's end, and "0...*" in B's end.

check http://en.wikipedia.org/wiki/Object_composition for more details.

If I read carefully, there is at the same time an inner stack and an inner single element. That's not a problem, because you can have several relationships between two same objects.

------------- ?           inner   ---------------
|           |-------------------> |             |
|           |                 1   |             |
| Class A   |                     |   Class B   |
|           | ?            stack  |             |
|           |-------------------> |             |
-------------                0..* ---------------

What I don't know is what to put on the question marks. Can a B be in the stack for several A at the same time? Multiplicity will depend on the answer.

About the object composition alluded by Sebastiaõ, it adds black diamonds on the left of the arrows in my drawing, but be aware that it means 1) that you are obliged to put 1 on my question marks, and 2) that if you destroy A, then you destroy all related Bs. Not sure it is the case for you.

Last note, as said by Sebastiaõ in his comment of his answer, if you put arrows, A will see B but B will not see A, while if you put a simple line, you can navigate either way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM