views:

27

answers:

1

Hello,

I want to show what my UserControl/Control is doing when I plug a list of data in it, what happens when the user press certain keys, selecting text etc...

I feel somehow a sequence diagramm is not really suited for showing several loops and doing stuff within the loops.

Am I wrong or how can I cope with that case?

+1  A: 

If you are talking about a loop, then you have a series of operations that take place for all elements in the loop.

I would model the operations done in the loop as a sequence diagram by itself, if the operation in the loop are fairly complex.

I don't think we can have rules of thumb here, but when the process with the loop itself is complex, and the loop is relatively less complex, we can have them in a single sequence diagram.

If the process that has the loop is not very complex, but the loop is complex, then I would draw a sequence diagram for the operations of the loop and have a note that this entire sequence is called by a loop.

You can also have both sequence diagrams if needed.

Update:
We have to add some notes to the diagram because it is not straightforward to denote a "condition" in a sequence diagram.
The validate is part is something like

do validation
if validation succeeds
   proceed to next (business or other) logic
if validation fails
   feedback to user (or some other logic)

+----+          +----+          +----------------+      +----------------+
|User|          | UI |          | Your Validator |      | Business Logic |
+----+          +----+          +----------------+      +----------------+
  |     select     |                   |                        |
  |--------------->|   doValidation    |                        |
  |                |------------------>|----+                   |
  |                |                   |    | Validate          |
  |                |                   |<---+                   |
  |                |                   |                        |
  |                |                   | (validation fails:     |
  |                |  Validation Fail  |  feedback to client)   |
  |                |<------------------|                        |
  |                |                   |                        |
  |                |                   |                        |
  |                |                   | (validation succeeds:  |
  |                |                   |  proceed to            |
  |                |                   |  business logic)       |
  |                |                   |                        |          
  |                |                   |    someLogic           |
  |                |                   |----------------------->|
  |                |                   |                        |

UPDATE 2
Why use sequence diagram in a case as mine? Because you still have to show the sequence of operations, and the developer still needs this information for coding :-)

With UML, as you probably already know, nothing is imposed. You are at your freedom to denote something in some fashion, provided your team also understands it the way you intended. These notes are also helpful.

I should have mentioned this before, some use an "option" fragment to denote a if else. This is more or less a note (I see it this way) but is perhaps more evident. I use them only when both the IF and the ELSE parts are both complex.

    +----+          +----+          +----------------+      +----------------+ 
    |User|          | UI |          | UI - Backend   |      |  Busines Logic |
    +----+          +----+          +----------------+      +----------------+
      |  Add Record    |                   |                        |
      |--------------->|  doinsertOrUpdate |                        |
      |                |------------------>|                        |
      |                |                   |      exists(record)    |
      |                |                   |----------------------->|
      |                |                   |                        |         
  ____|________________|___________________|________________________|__________
  |[Record exists]     |                   |                        |         |
  |   |                |                   |     Get Record         |         |
  |   |                |                   |----------------------->|         |
  |   |                |                   |                        |         |
  |   |                |                   |--------+               |         |
  |   |                |                   |        | Set UI Values |         |
  |   |                |                   |<-------+               |         |
  |   |                |                   |                        |         |
  |   |                |                   |   Update Record        |         |
  |   |                |                   |----------------------->|         |
  |   |                |                   |                        |         |
  |   |                | Send Message      |                        |         |
  |   |                |<------------------|                        |         |
  |   |                |  "Record found,   |                        |         |
  |   |                |   Updated"        |                        |         |
  |___|________________|___________________|________________________|_________|
      |                |                   |                        |
      |                |                   |                        |
______|________________|___________________|________________________|_________
| [Record does not     |                   |                        |         |
| exist]               |                   |                        |         |
|     |                |                   |--------+               |         |
|     |                |                   |        | Generate      |         |
|     |                |                   |        | Seqeuence     |         |
|     |                |                   |<-------+               |         |
|     |                |                   |                        |         |
|     |                |                   |   Create New Record    |         |
|     |                |                   |----------------------->|         |        
|     |                | Send Message      |                        |         |
|     |                |<------------------|                        |         |
|     |                |  "New Record      |                        |         |
|     |                |   Created"        |                        |         |
|_____|________________|___________________|________________________|_________|
      |                |                   |                        |
      |                |                   |                        |
      |                |                   |                        |

See this for an example using an alt block.

Nivas
How can I describe with a sequence diagramm, that the user IS selecting something and while selecting something I do validation?
Lisa
You generally have a actor in the sequence diagram. The "Message" from the actor to the first class (would be the UI in your case) would be "Select an Item", for example
Nivas
yes right, but DURING the selection a algorythm is started checking some chars WITHIN the selection/While the selection happens. How to describe this with a sequence diagramm?
Lisa
If I understand correctly, you have some sort of a list on a UI, and when the user selects one item from the list. when this selection happens, you do some validation/processing, and (probably) based on the result proceed with the next step. My explanation would fit this. Do I understand your scenario correctly?
Nivas
yes thats my scenario. The next step would be allow the selection or restrict it on chars.
Lisa
See my updated answer
Nivas
looks nice Nivas, one last question, where would set the Validation Succeed?
Lisa
The "validation failed" is a message to send to the UI as feedback to the user. If the validation succeeded you would proceed with your next step, right? I have done a minor update to the note. It is not really possible to show condtions and branching in sequence diagrams. We have to live with notes.
Nivas
and now the ultimate question, as you say "It is not really possible to show conditions and branching in sequence diagrams"... Why use it at all for such a case as mine?
Lisa