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

Chapter 6: Classes and Packages

Create and name a class for the nested class.

3.

In the browser, drag and drop the nested class onto the parent class.

To display a nested class on a Class diagram:

1.

Open a Class diagram.

2.

Select Query → Add Classes.

3.

Move the nested class from the Classes list box to the Selected Classes list box. The nested class will display with the format ParentClass::NestedClass.

4.

Click OK. The nested class will appear on the diagram, with the parent class name in parentheses.

To delete a nested class from the model:

1.

Open the class specification window for the parent class.

2.

Select the Nested tab.

3.

Right−click on the name of the nested class you wish to delete.

4.

Select Delete from the shortcut menu. The nested class will be removed from all Class diagrams.

OR

1.

Right−click the nested class in the browser.

2.

Select Delete.

Viewing the Interaction Diagrams That Contain a Class

When you need to change a class, it can be helpful to know exactly where in the system the class is being used. The two types of Interaction diagrams—Sequence diagrams and Collaboration diagrams—will let you

238

Chapter 6: Classes and Packages

know exactly where and how each class is being used. You can use the Report menu to see which Sequence and Collaboration diagrams contain objects of a particular class.

To view all Sequence and Collaboration diagrams that contain a certain class:

1.

Select the class on a Class diagram.

2.

Select Report → Show Instances.

3.

Rose will display a list of all Sequence and Collaboration diagrams that contain objects of that class, as shown in Figure 6.12. To open a diagram, double−click it in the list, or click the Browse button.

Figure 6.12: Viewing class instances

Setting Java Class Specifications

In Rose, Java classes have two specification windows: the standard specification, as described above, and a Java specification window. The Java specification window is used to set Java−specific fields, such as whether to generate a default constructor. Figure 6.13 shows the Java Class Specification window.

Figure 6.13: Java Class Specification window

Using this window, you can set the following:

239

Chapter 6: Classes and Packages

Name is equivalent to setting the name on the standard specification window.

Visibility controls whether the class is public and can be seen by all classes, or is visible only to classes in the same package. Possible values are Public or Package. Setting the value to Package is equivalent to setting the Export Control to Implementation in the standard specification window.

Abstract sets the class to be abstract, which implies that the class will never be directly instantiated. Setting this flag on the Java specification window is equivalent to checking the Abstract check box on the Detail tab of the standard specification window.

Final determines whether subclasses of the class may be created. If the Final flag is set to True, subclasses may not be created.

Generate is a set of four flags that determine whether to generate a finalize method, static initializer, instance initializer, and/or default constructor when generating code.

Interface sets whether this class is an interface. Checking this box is equivalent to setting the class stereotype to Interface in the standard specification window.

Generate Code controls whether Rose will generate code for this class. By default, this option is selected.

Disable Autosync will disable autosync for this class. Autosync is a feature that will automatically initiate the code−generation process when a Java element is modified. To enable or disable autosync for the entire model, select Tools Java Project Specification and then the Detail tab. At the bottom of the screen is an option for autosynchronization.

Constructor Visibility sets the visibility of the class's constructor to Public, Package, Private, or Protected.

Extends indicates whether the class is a subclass of another. If so, the parent class is listed.

Implements indicates whether the class implements the functionality listed in an interface. If so, the interface is listed.

DocComment provides comments for the class. This is equivalent to typing comments in the Documentation field of the standard specification window.

240

Chapter 6: Classes and Packages

Setting CORBA Class Specifications

As with Java, CORBA classes have their own specification window. You can use this window to set CORBA−specific information, such as enumeration attribute ordering or constant types and values. The specification window will vary slightly, depending upon the stereotype of the CORBA class you are working with. An example of the CORBA specification window is shown in Figure 6.14.

Figure 6.14: CORBA Class Specifications

Using the CORBA specification window, you can set the following information. Note that some of these options are available only for certain CORBA stereotypes.

Name sets the name of the class. This is equivalent to setting the name on the standard specification window.

Stereotype displays the stereotype of the class. To change the stereotype, open the standard specification window.

Implementation Type (Constant, Typedef) sets the data type of the constant or typedef.

Constant Value (Constant) sets the value of the constant.

Array Dimensions (Typedef) sets the dimensions of the typedef's declarator.

Attribute/Role Ordering (Enumeration, Union, Exception, Struct, Value, Custom Value) is used to set the order of the attributes in the class. When code is generated, the attributes will be generated in this order.

Inherits From (Value, Custom Value) sets the parent class, if the class is inherited.

241