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

Chapter 6: Classes and Packages

<number 1>..<number 2>

Between <number 1> and <number 2>

<number>..n

<number> or more

<number 1>,<number 2>

<number 1> or <number 2>

<number 1> , <number 2> .. <number 3>

Exactly <number 1> or between <number 2> and

 

<number 3>

<number 1> .. <number 2> , <number 3> .. <number

Between <number 1> and <number 2> or between

4>

<number 3> and <number 4>

To set class multiplicity:

 

1.

 

Open the class specification window.

 

2.

 

Select the Detail tab.

 

3.

From the Multiplicity drop−down list box, select the multiplicity. Or type in a multiplicity option that is not available in the drop−down list box.

Setting Storage Requirements for a Class

As you are building your model, you may want to note the amount of relative or absolute memory you expect each object of the class to require. The Space field in the class specification window is used for this purpose.

You cannot use the Space field for class utilities, instantiated class utilities, or parameterized class utilities.

To set class space:

1.

Open the class specification window.

2.

Select the Detail tab.

3.

Enter the storage requirements for the class in the Space field.

Setting Class Persistence

In Rose, you can generate DDL (data definition language) from your model. The DDL defines the structure of your database.

When you generate DDL, Rose will look for classes that have been set to Persistent. The Persistence field in the class specification window is used to specify whether a class is Persistent or Transient:

Persistent Suggests that the class will live beyond the execution of the application. In other words, the information in objects of the class will be saved to a database or some other form of persistent storage.

Transient Suggests that information in objects of the class will not be saved to persistent storage.

234

Chapter 6: Classes and Packages

You cannot use the Persistence field for class utilities, instantiated class utilities, or parameterized class utilities.

To set the persistence of a class:

1.

Open the class specification window.

2.

Select the Detail tab.

3.

Select Persistent or Transient in the Persistence area.

Setting Class Concurrency

Concurrency is used to describe how the class behaves in the presence of multiple threads of control. There are four concurrency options:

Sequential This is the default setting, and suggests that the class will behave normally (i.e., the operations will perform as expected) when there is only one thread of control, but the behavior of the class is not guaranteed in the presence of multiple threads of control.

Guarded Suggests that the class will behave as expected when there are multiple threads of control, but the classes in the different threads will need to collaborate with each other to ensure that they don't interfere with each other.

Active Suggests that the class will have its own thread of control.

Synchronous Suggests that the class will behave as expected, with multiple threads of control. There won't be any collaboration required with other classes, because the class will deal with the mutual exclusion on its own.

To set the concurrency of a class:

1.

Open the class specification window.

2.

Select the Detail tab.

3.

Select a concurrency radio button in the Concurrency area.

Creating an Abstract Class

An abstract class is a class that will not be instantiated. In other words, if Class A is abstract, there will never be any objects of Type A in memory. A class is defined as being abstract if at least one operation of the class is abstract. Rose does not enforce this rule.

235

Chapter 6: Classes and Packages

Abstract classes are typically used in inheritance structures. They hold some information and behavior that is common to some other classes. For example, we may have an Animal class, which has some attributes called height, color, and species. From this class, we inherit three other classes—Cat, Dog, and Bird. Each of these will inherit height, color, and species from the Animal class, and will have its own unique attributes and operations as well.

When the application is run, there are no animal objects created—all of the objects are cats, dogs, or birds. The Animal class is an abstract class that just holds the commonality between cats, dogs, and birds.

In UML, an abstract class is shown on a Class diagram with its name in italics:

To create an abstract class:

1.

Create a class using one of the methods described above.

2.

Open the class specification window.

3.

Select the Detail tab.

4.

Check the Abstract check box.

Viewing Class Attributes

In the next chapter, we'll talk in detail about adding, deleting, and working with attributes for a class. Part of the class specification window allows you to see the attributes that have already been created for a class. For additional information about attributes and operations, please refer to Chapter 7, "Attributes and Operations."

To view the class attributes:

1.

Open the class specification window.

2.

Select the Attributes tab. The attributes for the class, including the attribute visibility, stereotype, name, data type, and default value, will be listed on this tab.

Viewing Class Operations

In the next chapter, we'll discuss the details of adding, deleting, and maintaining the operations for a class. Here, in the class specification window, you can view the operations for a class. For additional information about operations, please refer to the next chapter.

To view the class operations:

1.

236

Chapter 6: Classes and Packages

Open the class specification window.

2.

Select the Operations tab. The operations for the class, including the operation visibility, stereotype, signature, and return type, will be listed on this tab.

Viewing Class Relationships

In Chapter 8, we will discuss in detail the different types of relationships you can add to classes. We'll talk about adding and deleting relationships and setting the detailed information about each relationship. In the class specification window, you can view all of the relationships that have been added to a class. For additional information about relationships between classes, please refer to Chapter 8.

To view the class relationships:

1.

Open the class specification window.

2.

Select the Relations tab. All of the relationships in which the class participates will be listed on this tab.

Using Nested Classes

In Rose, you can nest one class inside another. You can also nest additional classes inside the nested class, to as many levels of depth as necessary.

To create a nested class:

1.

Open the class specification window for the parent class.

2.

Select the Nested tab.

3.

Right−click anywhere inside the white space on the Nested tab.

4.

Select Insert from the shortcut menu.

5.

Type the name of the nested class.

OR

1.

Create and name the parent class.

2.

237