views:

47

answers:

2

I'm not sure how to model sub-methods in UML sequence diagram. When in the execution of one method another method is called (from the same class). I tried to give an example below:

How would you guys model this in UML (in a sequence diagram)?

..
car1.drive();
..

... in Car class:

..
drive(){
    this.startEngine();
}
startEngine(){
    this.getKey();
    this.insertKey();
}
..

a small begin:

objx     car1
----     ----
|         |
| drive() |
|-------->| startEngine()
|         |------------.
|         |            |
|         |<-----------.
|         |

But where comes the getKey() method? Must this be communicated via another sequence diagram? Or is there a way to include sub procedures?

A: 

You can have more than one class object lifeline on your diagram. You could even have your get key supplied by your actor object. The sequence diagram is there to help you decide on the order in which things occur. If your trying to demonstrate a real life situation, then the key is supplied by your driver actor. So GetKey() would be an internal process on the driver. The driver would then InsertKey() to the Car lifeline. The Car would VerifyKey() as an internal process and return whether the key was verified or not. If verified the driver would TurnKey() on the car. The car would internally StartEngine() and return a status message to the driver.

ChrisBD
Thanks for you reply, but my question is more about modelling sub-methods. How should I draw sub methods? I just gave an arbitrairy example about a car.
hsmit
+1  A: 

You use a self-message, as in the following:

Drive a Car

Note the "stacked" lifelines? Those are activation levels. It shows that the drive method calls startEngine, which then calls getKey followed by insertKey. I've left the returns implicit.

John Saunders