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

Chapter 6: Classes and Packages

Figure 6.8: Changing the default stereotype display

4.

In the Stereotype Display area, select the default display type (None, Label, Decoration, or Icon).

To add a new stereotype to the current Rose model:

1.

Open the class specification window.

2.

Type a new stereotype in the Stereotype field. The new stereotype will now be available in the drop−down list box as you add more classes, but only in the current Rose model.

3.

To add a new Stereotype icon for the new stereotype, see the online help ("Stereotype Configuration File").

Class Types

In design, we want to categorize our classes using the terminology of the particular programming language we are going to use. For example, if we are using Visual Basic, we may have stereotypes such as Class Module, Collection, or Form. If we are using Java, we would need stereotypes for session objects, servlets, interfaces, and so on.

Rose supports a number of different stereotypes for its different language options. This section describes the types of classes that are available. In the following sections, we'll discuss stereotypes for several of the languages supported by Rational Rose.

217

Chapter 6: Classes and Packages

Parameterized Class

A parameterized class, the first of the special types of classes we'll discuss, is a class that is used to create a family of other classes. Typically, a parameterized class is some sort of container; it is also known as a template. Not all languages directly support templates; you can use them in C++, Visual C++, or Ada.

For example, you may have a parameterized class called List. Using instances of the parameterized class, you can create some classes called EmployeeList, OrderList, or AccountList, as described below.

In UML, a parameterized class is displayed using this notation:

To add a parameterized class:

1.

Select the Parameterized Class button from the toolbar.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class.

OR

1.

Add a class to a Class diagram or to the browser using one of the methods listed above.

2.

Open the class specification window.

3.

In the Type field, select ParameterizedClass.

4.

Press OK.

OR

1.

Select Tools → Create → Parameterized Class.

2.

Click anywhere inside the diagram to place the new class.

3.

218

Chapter 6: Classes and Packages

Type the name of the class.

Setting Arguments for a Parameterized Class

The arguments for the class are displayed in the dashed−line box. The arguments are placeholders for the items that the parameterized class will contain. Using our example from the last section, we can replace the parameter item with a specific thing, such as Employee, to instantiate an EmployeeList class.

The argument can be another class, a data type, or a constant expression. You can add as many arguments as you need.

To add an argument:

1.

Open the class specification window by right−clicking the class and selecting Open Specification.

2.

Select the Detail tab.

3.

Right−click anywhere inside the white space in the Formal Arguments area.

4.

Select Insert from the shortcut menu.

5.

Type the argument name.

6.

Click below the Type column header to display a drop−down list of argument types, as shown in Figure 6.9. Select one of the types in the list or enter your own.

219

Chapter 6: Classes and Packages

Figure 6.9: Adding an argument to a parameterized class

7.

Click below the Default Value column header to enter a default value for the argument. A default value is not required.

To delete an argument:

1.

Open the class specification window.

2.

Select the Detail tab.

3.

Right−click on the argument you wish to delete.

4.

Select Delete from the shortcut menu.

Instantiated Class

An instantiated class is a parameterized class that has actual values for the arguments. From our last example, we know that we have a list of items. Now, we can supply a value for the Items argument, to see that we have a list of employees. UML notation for an instantiated class is a class with the argument name enclosed in angle brackets (< >):

220

Chapter 6: Classes and Packages

The number of actual values in an instantiated class must match the number of formal arguments in the parameterized class that it instantiates. If an argument is another class, then there should be a dependency on that class.

To add an instantiated class:

1.

Select the Instantiated Class button from the toolbar.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class with the arguments in angle brackets (< >).

OR

1.

Add a class to a Class diagram or to the browser using one of the methods listed above.

2.

Open the class specification window.

3.

In the Type field, select InstantiatedClass.

4.

Click OK.

OR

1.

Select Tools → Create → Instantiated Class.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class.

Class Utility

A class utility is a collection of operations. For example, you may have some mathematical functions—squareroot(), cuberoot(), and so on—that are used throughout your system but don't fit well into any particular class. These functions can be gathered together and encapsulated into a class utility for use by

221

Chapter 6: Classes and Packages

the other classes in the system.

Utility classes are frequently used to extend the functionality provided by the programming language or to hold collections of generic, reusable pieces of functionality that are used in many systems.

A class utility will appear as a shadowed class on the diagram with this symbol:

To add a class utility:

1.

Select the Class Utility button from the toolbar.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class.

OR

1.

Add a class to a Class diagram or to the browser using one of the methods listed above.

2.

Open the class specification window.

3.

In the Type field, select ClassUtility.

4.

Press OK.

OR

1.

Select Tools → Create → Class Utility.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class.

222

Chapter 6: Classes and Packages

Parameterized Class Utility

A parameterized class utility is a parameterized class that contains a set of operations. It is the template that is used to create class utilities. It appears on a Class diagram with the following symbol:

To add a parameterized class utility:

1.

Select the Parameterized Class Utility button from the toolbar.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class.

OR

1.

Add a class to a Class diagram or to the browser using one of the methods listed above.

2.

Open the class specification window.

3.

In the Type field, select ParameterizedClassUtility.

4.

Press OK.

OR

1.

Select Tools → Create → Parameterized Class Utility.

2.

Click anywhere inside the diagram to place the new class.

3.

Type the name of the class.

Instantiated Class Utility

An instantiated class utility is a parameterized class utility that has values set for the parameters. It appears on a Class diagram as follows:

223