Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 6: Classes and Packages

the steps in the flow of events (not a one−for−one mapping, but the sequence should be the same). The objects in the Sequence and Collaboration diagrams should map to the classes in the Class diagrams. A single class may appear on many Sequence and Collaboration diagrams and may even appear several times on the same Sequence or Collaboration diagram as different objects of the same class.

Creating Class Diagrams

In Rose, Class diagrams are created in the Logical view. Again, you can create as many Class diagrams as you need to provide a complete picture of your system.

When you create a new model, Rose automatically creates a Main Class diagram under the Logical view. Typically, you use this diagram to display the packages of classes in your model. You can create additional Class diagrams directly underneath the Logical view or within any existing package.

In Rose 2002, you can set a default Main diagram for each package, even if the diagram is not titled "Main." In the browser, right−click the diagram you wish to make the default, and select the Set as Default Diagram option.

To access the Main Class diagram:

1.

Click the + (plus sign) next to the Logical View entry in the browser to open it.

2.

The Main Class diagram will be visible. Note that Class diagrams in Rose have the following icon on their right:

3.

Double−click the Main Class diagram to open it.

Note When you first start Rose and load a model, the Main Class diagram will automatically open. To create a new Class diagram:

1.

Right−click the Logical View entry in the browser.

2.

Select New → Class diagram from the shortcut menu.

3.

Enter the name of the new diagram.

4.

Double−click the diagram in the browser to open it.

To open an existing Class diagram:

1.

Locate the Class diagram in the Logical view of the browser.

2.

205

Chapter 6: Classes and Packages

Double−click the diagram to open it.

OR

1.

Select Browse → Class Diagram. The window displayed in Figure 6.2 will appear.

Figure 6.2: Opening an existing Class diagram

2.

In the Package list box, select the package that contains the diagram you want to open.

3.

In the Class Diagrams list box, select the diagram you want to open.

4.

Press OK.

To add an item to a Class diagram, use the Class Diagram toolbar buttons to add items to the diagram. Or, you can go to Tools → Create and select the item you wish to create. In the following sections, we'll describe how to add the various items to a Class diagram.

There are two ways to remove an item from the diagram. To remove an item from the current diagram only:

1.

Select the item on the diagram.

2.

Press Delete.

To remove an item from the model:

1.

Select the item on the diagram.

2.

Select Edit → Delete from Model, or press Ctrl+D.

OR

1.

Right−click the item in the browser.

2.

206

Chapter 6: Classes and Packages

Select Delete from the shortcut menu.

Deleting Class Diagrams

As you add and remove classes from your model, you may need to delete some of the Class diagrams you have created. In Rose, you can delete Class diagrams using the browser. When you delete a diagram, the classes contained on the diagram will not be deleted. They will still exist in the browser and on other diagrams.

To delete a Class diagram:

1.

Right−click the Class diagram in the browser.

2.

Select Delete from the shortcut menu.

Organizing Items on a Class Diagram

As more and more classes and relationships are added to a diagram, it can become very cluttered and difficult to read. Rose provides the option of automatically arranging all of the classes on the diagram.

As you add attributes and operations to a class or resize the classes on the diagram, you may end up with a class that is too large or too small. Rose can automatically resize all of the classes to fit the text within them. Using these two options, you can turn a diagram that looks like Figure 6.3 into a diagram that looks like Figure 6.4.

Figure 6.3: Class diagram without resizing and automatic layout

207

Chapter 6: Classes and Packages

Figure 6.4: Class diagram with resizing and automatic layout

To lay out the items on a Class diagram, select Format → Layout Diagram. Rose will automatically align the classes in the diagram.

To resize the items on a Class diagram, select Format → Autosize All. Rose will automatically resize each class on the diagram to fit the class name, attributes, and operations within the class.

Using the Class Diagram Toolbar

In this chapter, we'll discuss how to add classes to the model and to a diagram. In the following sections, we'll talk about the options provided by each of these toolbar buttons, with the exception of those dealing with relationships. We will discuss the relationship toolbar buttons in Chapter 8, "Relationships."

If you don't see all of these buttons on the toolbar, right−click the toolbar and select Customize. From this dialog box, you can add each of the buttons listed in Table 6.1.

Table 6.1: Icons Used in the Class Diagram Toolbar

Icon

Button

Purpose

 

Selects or Deselects an Item

Returns the cursor to an arrow to select an item.

 

 

 

 

Text Box

Adds a text box to the diagram.

 

 

 

 

Note

Adds a note to the diagram.

 

 

 

 

Anchor Note to Item

Connects a note to an item on the diagram.

 

 

 

 

Class

Adds a new class to the diagram.

 

 

 

 

Interface

Adds a new interface class to the diagram.

 

 

 

 

Association

Draws an association relationship.

 

 

 

 

Aggregation

Draws an aggregation relationship.

 

 

 

208