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

Chapter 6: Classes and Packages

 

Object View

 

Relational Table

 

Relational View

 

VARRAY

XML

DTD Element

 

DTD Entity

 

DTD Sequence Group

 

DTD Notation

Class Specifications

 

Most of the options that you can set for a class are available on the class specification window, as shown in Figure 6.10. For example, this window allows you to set the class stereotype, visibility, and persistence. In the following sections, we'll talk about each of the options available on the tabs of this window.

Figure 6.10: Class specification window

If you are examining the specifications for a Java, XML, or CORBA class, the specification window that appears is slightly different, as shown below in Figure 6.11. All of the options on this window are also available through the standard specification window.

230

Chapter 6: Classes and Packages

Figure 6.11: Java specification window

To open the class specifications:

1.

Right−click the class on a Class diagram.

2.

Select Open Specification from the shortcut menu.

OR

1.

Right−click the class in the browser.

2.

Select Open Specification from the shortcut menu.

OR

1.

Select the class on a Class diagram.

2.

Select Browse → Specification, or press Ctrl+B.

Naming a Class

Each class in your Rose model should be given a unique name. Most organizations have a naming convention to follow when naming a class. In general, however, classes are named using a singular noun. In our airline reservation system, for example, we may have a class called Flight and another called Airplane. (We would not call them flights and airplanes.)

231

Chapter 6: Classes and Packages

Class names typically do not include spaces. This is for practical reasons as well as readability—many programming languages do not support spaces in class names. Try to keep your class names relatively short. While ListOfEmployeesThatAreOnProbation is a very good description of what that class does, it can make the code rather unreadable. EmployeeList might be a better class name in this case.

Whether to use uppercase or lowercase letters really depends on your organization. If we have a class that is a list of employees, it could be called employeelist, Employeelist, EmployeeList, or EMPLOYEELIST. Again, each company typically has a naming convention. Just be sure that whichever approach is decided upon is used for all classes.

To name a class:

1.

Select the class in the browser or on the Class diagram.

2.

Type the class name.

OR

1.

Open the class specification window.

2.

In the Name field, enter the class name.

To add documentation to a class:

1.

Select the class in the browser.

2.

In the documentation window, type the class documentation.

OR

1.

Open the class specification window.

2.

In the specification window, type the information in the Documentation area.

Setting Class Visibility

The Visibility option determines whether or not a class can be seen outside of its package. It is controlled through the Export Control field in the specification window. There are three visibility options for a class:

Public Suggests that the class can be seen by all of the other classes in the system.

Protected or Private Suggests that the class can be seen in nested classes, friends, or within the same class.

232

Chapter 6: Classes and Packages

Package or Implementation Suggests that the class can be seen only by other classes in the same package.

To set class visibility:

1.

Right−click the class in the browser or on a Class diagram.

2.

Select Open Specification from the shortcut menu.

3.

Set the export control to Public, Protected, Private, or Implementation.

If a class has protected, private, or package visibility, it cannot be seen by classes in other packages. An access violation occurs in one of two situations:

When there is a relationship between two classes in different packages, but there is no dependency relationship between the packages themselves

When there is a relationship between classes in different packages, and the supplier class has implementation visibility

In Rose, open a Class diagram and select Report Show Access Violations to check for one of these two problems.

Setting Class Multiplicity

The Multiplicity field gives you a place to set the number of instances that you expect to have of a class. In the employee tracking system, we can probably expect to have many instances of the Employee class—one for John Doe, one for Fred Smith, and so on. The multiplicity for the Employee class, then, would be n.

Control classes, however, frequently have a multiplicity of 1. As you're running the application, you probably need only one instance of a security manager.

In Rose, the following multiplicity options are available in the drop−down list box:

Multiplicity

Meaning

n (default)

Many

0..0

Zero

0..1

Zero or one

0..n

Zero or more

1..1

Exactly one

1..n

One or more

Or you can enter your own multiplicity, using one of the following formats:

Format

Meaning

<number>

Exactly <number>

233