Object Diagrams


 

Suppose that an application has a 500 x 500 pixel drawing area that is dived into three regions as follows:

  • Approximately half of the drawing area, on the right side, is a single region bordered by a rectangle. The upper left hand corner of this region is at coordinates (260,0), its width is 240 pixels, and it height is 500 pixels.
  • The left side of the drawing area is subdivided into two equally sized regions, each of which is bordered by a rectangle. The upper left-hand corner of the top subregion is at coordinates (0,0). The upper-left corner of the botton subregion is at coordinates (0,260). Each subregion has a width and height of 240 pixels.

The borders should be drawn with a thickness of five pixels.

Using the classes for a drawing tool mentioned earlier, the drawing area could be implemented by a Canvas object, each of the three drawing regions by Rectangle objects, and the border width would be handled by associating an appropriately initialized Pen object with the Canvas object.

However, the class diagrams for these classes does not convey some essential information about the structure of the drawing area. For example, the class diagram does not indicate that the Shapes known by the Canvas are specifically Rectangles, or that there are exactly three Rectangle objects known by the Canvas; nor does it show the location of each Rectangle object, or the value of the Pen object's width. Answers to questions such as these are provided by an object diagram.

An object diagram for the drawing areas described above is shown below. The drawingArea object is an instance of the Canvas class and has pointers to three Rectangle objects (upperLeft, lowerLeft, atRight). Each of the Rectangle objects has a composed Location object. Since the diagram depicts objects, the actual values of each Rectangle object's Location, height, and width can be shown in the diagram. Also, the width of the Pen object (aPen) used by the drawingArea object can be shown explicitly.


An Object Diagram

 




©1998 Prentice-Hall, Inc.
A Simon & Schuster Company
Upper Saddle River, New Jersey 07458

Legal Statement