Interaction Diagrams

Class Diagrams show static relationships between classes. In other words, they do not show us any activity. Although very useful, sometimes I need to show how the objects instantiated from these classes actually work together.

The UML diagrams that show how objects interact with each other are called Interaction Diagrams. The most common type of Interaction Diagram is the Sequence Diagram, such as shown in Figure 2-8.

Figure 2-8. Sequence Diagram for the shapes program.


Sequence Diagrams are read from top to bottom.

  • Each rectangle at the top represents a particular object. Although many of the rectangles have class names in them, notice how there is a colon in front of the class name. Some of the rectangles have other names—for example, shape1:Square.

  • The boxes at the top give the class name (to the right of the colon) and optionally, a name of the object (before the colon).

  • The vertical lines represent the lifespan of the objects. Unfortunately, most UML drawing programs don't support this and draw the lines from the top to the bottom, leaving it unclear when an object actually comes into existence.

  • I show objects sending messages to each other with horizontal lines between these vertical lines.

  • Sometimes returned values and/or objects are explicitly shown and sometimes it is just understood that they are returned.

For example, in Figure 2-8,

  • At the top I see that Main sends a “get shapes” message to the ShapeDB object (which isn't named). After being asked to “get shapes,” the ShapeDB:

    - Instantiates a collection

    - Instantiates a square

    - Adds the square to the collection

    - Instantiates a circle

    - Adds the circle to the collection

    - Returns the collection to the calling routine (the Main)

I read the rest of the diagram in this top-down fashion to see the rest of the action. This diagram is called a Sequence Diagram because it depicts the sequence of operations.

Object:Class notation.

In some UML diagrams, you want to refer to an object with the class from which it is derived. This is done by connecting them with a colon. In Figure 2-8, I show shape1:Square refers to the shape1 object which is instantiated from the Square class.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.43.211