Julian J. Tejera
Julian J. Tejera

Reputation: 1021

How to represent a loop in a Class Diagram

I was wondering if anyone could explain to me how to represent a loop from UML sequence diagram in a Class Diagram.

Here's the Sequence Diagram: enter image description here

and here's the Class Diagram I made from the Sequence Diagram

enter image description here

Upvotes: 0

Views: 4075

Answers (2)

Clifford
Clifford

Reputation: 93476

UML diagram taxonomy is divided into Behavoural and Structural diagrams. A class diagram is structural, you would need a behavioural diagram to describe loop semantics.

UML diagram types

UML 2.x sequence diagrams have explicit notation for loops, while loop semantics may also be expressed in activity or state-machine diagrams.

In your sequence diagram, the loop is inside the :microndas::iniciar() method/message, and is therefore part of the description of that rather than the class diagram. You would attach a behavioural diagram to the :microndas class to describe this behaviour is necessary, though your existing sequence diagram may already suffice.

UML is about expressing different "views" or "aspects" of a system, It is wrong thinking to try to express all that is in one diagram type in another - if that were possible we'd only need one diagram type, and I do not want to go back to designing everything with a flow-chart; for one thing the stationary shop no longer sells those stencils!

Upvotes: 3

DXM
DXM

Reputation: 4543

You don't.

Class diagrams are not about code execution; they are about the structure of your classes. In other words, your sequence diagram has a time component that shows the reader what happens during the execution. Class diagrams, on the other hand, are supposed to show class relationships (i.e. which class is associated/uses/derives from another class).

Upvotes: 5

Related Questions