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

Chapter 6: Classes and Packages

Rose will add the selected class(es) to the open diagram.

To add a class to the browser:

1.

Right−click Logical View in the browser. To add a class to a package, right−click the package name.

2.

From the shortcut menu, select New → Class. To add a class utility or an interface, select New → Class Utility or New → Interface. The new class, called NewClass by default, will appear in the browser.

3.

Select the new class and type its name.

4.

To then add the new class to a Class diagram, drag it from the browser to the open diagram.

Class Stereotypes

A stereotype is a mechanism you can use to categorize your classes. Say, for example, you want to quickly find all of the forms in the model. You could create a Form stereotype, and to find your forms later, you would just need to look for the classes with the Form stereotype.

This feature helps you more thoroughly understand the responsibilities of each class in your model. Classes with a Form stereotype are responsible for displaying information to the user and receiving information from the user. Classes with the Visual Basic Collection stereotype are responsible for grouping entities together into a dataset or other type of collection. Each stereotype has its own types of responsibilities.

Stereotypes also help in the code−generation process. When Rose generates code, it looks at the class stereotypes to determine what type of class to create in the target programming language.

Rose comes with a number of built−in stereotypes. Some are used during the analysis process, when you haven't yet determined what language you will be using. Others are specific to a particular language, and are used in the detailed design process. These different types of stereotypes are important; they allow you to start assigning responsibilities to classes in the analysis process without tying the model to a specific language.

In this section, we will discuss the stereotypes for analysis and language−dependent design that come with Rose.

Analysis Stereotypes

During analysis, you may want to categorize your classes according to the functions they perform. There are three primary class stereotypes in UML that are used for analysis: boundary, entity, and control.

212

Chapter 6: Classes and Packages

Boundary Classes

Boundary classes are those classes that lie on the boundary between your system and the rest of the world. These would include all of your forms, reports, interfaces to hardware such as printers or scanners, and interfaces to other systems. The UML representation of a boundary class looks like this:

To find and identify boundary classes, you can examine your Use Case diagram. At a minimum, there must be one boundary class for every actor–use case interaction. The boundary class is what allows the actor to interact with the system.

You don't necessarily have to create a unique boundary class for every actor–use case pair. For example, say you have two actors that both initiate the same use case. They might both use the same boundary class to communicate with the system.

213

Chapter 6: Classes and Packages

Entity Classes

Entity classes hold information that you may save to persistent storage. In our airline reservation system, the Flight class is a good example of an entity class. Entity classes are usually found in the flow of events and in Interaction diagrams. They are the classes that have the most meaning to the user and are typically named using business−domain terminology.

Look at the nouns in your flow of events. Many of these nouns will be the entity classes in the system. Another good place to look is in the database structure. If some database design has already been done, look at the table names. An entity class may need to be created for a table. While the table holds a record's information permanently, the entity class will hold the information in memory while the system is running.

In UML, entity classes are represented by the following symbol:

By tying our database design to the object model, we can trace many of the fields in the database back to a requirement. The requirements determine the flow of events. The flow of events determines the objects, the classes, and the attributes of the classes. Each attribute in an entity class may become a field in the database. Using this approach, we can trace each database field back to a requirement and reduce the risk of collecting information no one uses.

Control Classes

Finally, let's take a look at control classes. Control classes are responsible for coordinating the efforts of other classes. They are optional, but if a control class is used, there is typically one control class per use case, which controls the sequencing of events through the use case. On an Interaction diagram, a control class has coordinating responsibilities, as you can see in Figure 6.7.

Figure 6.7: Control class on a Sequence diagram

214

Chapter 6: Classes and Packages

Notice that the control class doesn't carry out any functionality itself, and other classes don't send many messages to it. Instead, it sends out a lot of messages. The control class simply delegates responsibility to the other classes. Control classes are responsible for knowing and carrying out the business rules of an organization. They execute alternative flows and know what to do in case of an error. For this reason, control classes are sometimes called manager classes. In UML, control classes are drawn using the following symbol:

There may be other control classes that are shared among several use cases. For example, we may have a SecurityManager class that is responsible for controlling events related to security. We may have a TransactionManager class that is responsible for coordinating messages related to database transactions. We may have other managers to deal with other common functionality, such as resource contention, distributed processing, or error handling.

These types of control classes can be a good way to isolate functionality that is used across the system. Encapsulating security coordination, for example, into a SecurityManager can help minimize the impact of change. If the sequencing of the security logic needs to change, only the SecurityManager will be affected.

Additional Class Stereotypes

In addition to the stereotypes mentioned above, you can add your own stereotypes to the model. In the Stereotype field, you can enter the new stereotype, and from that point on, it will be available in your current Rose model.

To assign a class stereotype:

1.

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

2.

Select a stereotype from the drop−down list box or type in the stereotype name.

To display the stereotype name on the diagram:

1.

Right−click a class on a Class diagram.

2.

From the shortcut menu, select Options → Stereotype Display → Label. The stereotype name will appear, enclosed in double angle brackets (<< >>), just above the class name.

215

Chapter 6: Classes and Packages

To display the Stereotype icon on the diagram:

1.

Right−click a class on a Class diagram.

2.

From the shortcut menu, select Options → Stereotype Display → Icon.

3.

The representation of the class will change to the appropriate icon. This example shows the icon for an Interface class:

Note Not all of the stereotypes have icons. If there is no icon for a stereotype, only the stereotype name will appear on the diagram.

To turn off the stereotype display on the diagram:

1.

Right−click a class on a Class diagram.

2.

From the shortcut menu, select Options → Stereotype Display → None. The class will still have a stereotype, visible in the class specification window, but the stereotype will not display on the diagram.

To change the default stereotype display option:

1.

Select Tools → Options.

2.

Select the Diagram tab.

3.

In the Compartments area, as shown in Figure 6.8, select or deselect the Show Stereotypes check box to control whether or not the stereotype will display.

216