Modeling behavior

The class diagram models the static associations and dependencies among classes. UML diagrams that model interactions among objects are :

  1. Sequence diagram
  2. Activity diagram
  3. State diagram
  4. Collaboration diagram

We will look a the first three, which can are better suited for object-oriented analysis.

The Sequence diagram

Sequence diagrams can model the sending of messages between objects and their sequencing in time. Along the top of the diagram are instances (objects) of the various classes that a re involved. A dashed line descends from each one, indicating the passage of time. A solid bock shows the existence of an object when messages are being sent. A message is a horizontal line between the sold blocks. The label on the line shows the message being sent and the arrow indicates the direction. In the diagram below, three objects (and an actor) interact for one use case - registering a student in a course. The numbering scheme on the messages are another way that the passage of time is indicated. Each subordinate number shows a subordinate message.

A more complex version of the diagram, with checking of prerequisites is below:

State diagrams

As their name indicates state diagrams are excellent for analyzing systems where transitions between states are part of the design. A state is a labeled rectangle with rounded corners. A transition is a solid line with and arrow indicating direction. It can be labeled with an event, an action or a guard (a condition for the transition). A solid black circle is the entry point, a solid circle with another circle around it is an exit point. Some examples are;

Activity diagrams

Activity diagrams are good for showing flow of control, especially where concurrentcy may be involved. Actions or events are shown as labeld rounded rectangles, and arrows between them are flow of control. They can have guards (conditions) on them. If the flow forks this is shown by a solid line with two (or more) flows exiting it. When flows join the reverse is shown. To make it more object-oreiented, the daigram can be organized into swin lanes, with each line containing the activities of a single object. An example is:

Collaboration diagrams

For a good tutorial on collaboration diagrams, see this link.