Modeling Objects and Classes on Diagrams






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 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: Object diagram example.

The diagram in Figure 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, 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.

Figure helps you choose when to use each type of diagram.

Figure: 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.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows