In a sequence diagram i am trying to model a loop that creates a bunch of objects. i have found little information online regarding the creation of multiple objects in an SD diagram so i turn to you.
The classes are Deck and Card
Cards are created by fillDeck(), which is called by the constructor of Deck (FYI the objects are stored in an arraylist in Deck).
There are many types of cards with varying properties. Suppose i want 8 cards of type A to be made, 12 of type B and 3 of type C
How would i go about modelling such a thing? this is the idea i have in mind so far, but it is obviously incomplete.
Hope someone can help! thanks!
+------+ | Deck | +------+ | +--+-------+--------------+ | loop 8x / | +--+-----+ +----------+ | | |-------->| Card(A) | | | | +-----+----+ | +--+----------------------+ | | +--+--------+------|-----------------------+ | loop 12x / | | +--+------+ | +---------+ | | |------------------------->| Card(B) | | | | | +----+----+ | |--+---------------------------------------+ | | | | +--+-------+----------------------------------------------+ | loop 3x / | | | +--+-----+ | | +---------+ | | |--------------------------------------->| Card(C) | | | | | | +----+----+ | |--+------------------------------------------------------+ | | | |
"A sequence diagram describes an Interaction by focusing on the sequence of Messages that are exchanged, along with their corresponding OccurrenceSpecifications on the Lifelines." (UML standard) A lifeline are defined by one object. But that doesn't mean you must keep all objects in lifelines. You should show only these lifelines, that are exchanging messages you are thinking about.
And you needn't show all messages sequences logic on one diagram. In one SD normally you are showing one Interaction
. Or maybe a few of them, if they are simple.
So, if your SD is showing one logical concept, it is correct. If there will be another interaction between some objects, you will draw another SD for this interaction, and there will be only objects participating in this second interaction.
UML standard 2.5. Figure 17.25 - Overview of Metamodel elements of a Sequence Diagram