Modeling Objects and Classes on Diagrams


You have two main types of static diagram in UML—class diagrams and object diagrams. Class diagrams show classes and associations, aggregations, and generalizations. Pure object diagrams just show instances of classes and their links to other instances. Of course, you can also show classes and objects on the same diagram, but this is rarely done. We use these different diagram types for specific purposes.

 Tip   If you use a UML modeling tool, take a close look at the different types of diagrams that it supports. If you do not see an object diagram, then the modeling tool probably lets you place objects on class diagrams.

Most of the time you use class diagrams; they provide the broadest way of showing what you’re modeling. They’re also the most useful diagrams you can produce, because the code that UML tools generate is based on the class diagram.

Pure object diagrams simply show instances and links—the objects and the connections between objects. (For more on links see chapter 4.) For complex modeling, you have to show many instances and links on a single diagram. But, the class diagram would be quite simple. Figure 7-1 shows you just what we’re saying. An instance of the Supplier class called ace1 links up with two instances of the Invoice class, a1 and a2. Both instances a1 and a2 are bills that were sent out in the past because they play the role of pastBill. These two invoices were paid from an instance of the SupplierAccount class called aceAcc. Another instance of the Supplier class, generalAirF, is linked to a different set of invoices. From the diagram you see that the instance b4 of the Invoice class plays the role of the currentBill.


Figure 7-1: Object diagram example.

The diagram in Figure 7-1 illustrates two different cases for suppliers and their invoices. In one case the supplier ace1 has no current bill. In the other case generalAirF has a current bill. This object diagram is an illustration of the class diagram shown in Figure 7-7, later in this chapter.

 Tip   Pure object diagrams are good for showing a simple example of what you mean by a class diagram. We sometimes have one or two pure object diagrams for a software project; they help give managers an idea of what’s going on.

You can also build a hybrid class/object diagram. You’ll find this most useful when you want to show your classes—and also show one or two example instances of no more than a few of those classes.

Table 7-1 helps you choose when to use each type of diagram.

Table 7-1: Choosing a Diagram Approach

Diagram Type

Purpose

Pure class diagram

Show classes, associations, aggregations, and generalization.

Arrange classes for code generation in a UML tool.

Pure object diagram

Show management a specific example.

Consider what instances you have at runtime (also use a communication diagram).

Describe pre- and postconditions of a piece of behavior (what is true before and after some behavior is performed).

Show a setup for test runs.

Hybrid class object diagram

Show examples of specific classes that are hard to understand.




UML 2 for Dummies
UML 2 For Dummies
ISBN: 0764526146
EAN: 2147483647
Year: 2006
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net