1. Trang chủ
  2. » Công Nghệ Thông Tin

Mastering UML with Rational Rose 2002 phần 5 ppt

71 276 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 71
Dung lượng 0,93 MB

Nội dung

Setting the Operation Return Class The return class of an operation is the data type of the operation's result. For example, say we have an operation called Add, which takes as parameters two strings, X and Y. The operation will convert X and Y to integers, add them, and return the result as an integer. The return class of Add will be "integer." When specifying the return class, you can either use built−in data types of your programming language—such as string, char, or integer—or use classes that you have defined in your Rose model. To set the operation return class: 1. Right−click the operation in the browser. 2. Select Open Specification from the shortcut menu. 3. Select a return class from the drop−down list box, or enter a new return type. OR 1. Select the operation on a Class diagram. 2. After the operation name, enter a colon, followed by the return type. For example, if you have an operation called Print that should return an integer, your Class diagram will look like this: Setting the Operation Stereotype As with other model elements, operations can be stereotyped to classify them. As discussed above, there are four commonly used operation stereotypes: Implementor Operations that implement some business logic. Manager Constructors, destructors, and memory management operations. Access Operations that allow other classes to view or edit attributes. Typically, these are named Get<attribute name> and Set<attribute name>. Helper Private or protected operations used by the class but not seen by other classes. Chapter 7: Attributes and Operations 274 Setting stereotypes for operations isn't required to generate code. However, stereotypes can help improve the understandability of the model. Also, they can help you to be sure that you haven't missed any operations. To set the operation stereotype: 1. Right−click the operation in the browser. 2. Select Open Specification from the shortcut menu. Rose will open the operation specification window. 3. Select a stereotype from the drop−down list box or enter a new stereotype. OR 1. Select the operation in the browser. 2. Single−click the operation again to edit the name. Before the name, the double angle bracket characters (<<>>) will appear: 3. Type the stereotype between the brackets. Chapter 7: Attributes and Operations 275 Setting the Operation Visibility As we discussed before, visibility has to do with how information and behavior is encapsulated in a class. There are four visibility options for operations. (To familiarize yourself with the way these are represented visually, see Table 7.2.) Public Suggests that the operation is visible to all other classes. Any other class can request that the operation be executed. Private Means that the operation is not visible to any other class. Protected Suggests that the class and any of its descendants have access to the operation. Package or implementation Indicates that the operation is public, but only to classes in the same package. While attributes are typically private or protected, operations may be public, private, protected, or package. When making this decision, think about what other classes, if any, will need to know that the operation exists. When you generate code, Rose will generate the appropriate visibility. For example, the code generated for the class above is shown in Figure 7.8. Chapter 7: Attributes and Operations 276 Figure 7.8: Operation visibility in generated code As mentioned earlier in this chapter, you can use either UML or Rose notation on a Class diagram. See the upcoming numbered steps for a description of how to switch between these two notations. Refer to Figure 7.4 to see a class using UML visibility notation and to Figure 7.5 to see the same class using Rose visibility notation. To revisit a summary of the possible visibility options, including their Rose and UML notations, see Table 7.2. To set the operation visibility: 1. Right−click the operation in the browser. 2. Select Open Specification from the shortcut menu. The Operation Specification window will appear. 3. In the Export Control field, select the operation's visibility: Public, Protected, Private, or Implementation. By default, all operations have public visibility. OR 1. Select the operation on a Class diagram. 2. If you are using UML notation for visibility, single−click the icon (+, −, or #) next to the operation. Select a visibility option from the list of Rose visibility icons that appears. 3. Chapter 7: Attributes and Operations 277 If you are using Rose notation for visibility, single−click the Rose visibility icon to the left of the operation name. Select a visibility option from the list of icons that appears. Adding Arguments to an Operation Operation arguments, or parameters, are the input data the operation receives. An Add operation, for example, may take two arguments, X and Y, and add them together. There are two pieces of information to supply for each argument. The first is the argument name. The second is its data type. On a Class diagram, the arguments and data types appear in parentheses after the operation name: If you'd like, you can also specify a default value for each argument. If you include a default value, the UML notation is: Operation name(argument1 : argument1 data type = argument1 default value) : operation return type When you generate code, Rose will generate the operation name, arguments, argument data types, argument default values, and return type. Rose will also create comments if any documentation was added to the operation. To add an argument to an operation: 1. Open the operation specification window. 2. Select the Detail tab. 3. Right−click in the Arguments box, then select Insert from the menu. 4. Chapter 7: Attributes and Operations 278 Enter the name of the argument, as shown in Figure 7.9. Figure 7.9: Operation arguments 5. Click on the Type column and enter the data type of the argument. 6. Click on the Default column and enter the default for the argument, if desired. To delete an argument from an operation: 1. Open the operation specification window. 2. Select the Detail tab. 3. Right−click the argument to be deleted in the Arguments box, and then select Delete from the menu. 4. Confirm the deletion. Specifying the Operation Protocol The operation protocol describes what operations a client may perform on the object, and in which order the operations must be executed. For example, if operation A should not be executed until operation B has been Chapter 7: Attributes and Operations 279 executed, you can note this in the Protocol field of operation A. The information you enter here will not have an impact on what code is generated for the operation. The operation protocol screen is shown in Figure 7.10. Figure 7.10: Operation protocol To specify the operation protocol: 1. Open the operation specification window. 2. Select the Detail tab. 3. Enter the protocol in the Protocol field. Specifying the Operation Qualifications This field lets you identify any language−specific qualifications for the operation. It will not affect the code generated for the operation. To specify the operation qualifications: 1. Open the operation specification window. 2. Select the Detail tab. 3. Chapter 7: Attributes and Operations 280 Enter the qualifications in the Qualification field. Specifying the Operation Exceptions The operation Exceptions field gives you a place to list the exceptions that the operation may throw. In some languages, the exception information will affect the code generated for the operation. For example, Figure 7.11 is some Java code generated with exception information. Figure 7.11: Operation exceptions in generated code To specify the operation exceptions: 1. Open the operation specification window. 2. Select the Detail tab. 3. Enter the exceptions in the Exceptions field. Specifying the Operation Size The Size field is a place to note how much memory you expect the operation to require at runtime. To specify the operation size: 1. Open the operation specification window. 2. Select the Detail tab. 3. Enter the size in the Size field. Specifying the Operation Time The operation time is the approximate amount of time you expect this operation to require as it executes. To specify the operation time: 1. Open the operation specification window. 2. Select the Detail tab. 3. Enter the time in the Time field. Chapter 7: Attributes and Operations 281 Specifying the Operation Concurrency The Concurrency field specifies how the operation will behave in the presence of multiple threads of control. There are three concurrency options: Sequential Suggests that the operation will run properly only if there is a single thread of control. The operation must run to completion before another operation may be run. Guarded Suggests that the operation will run properly with multiple threads of control, but only if the classes collaborate to ensure that mutual exclusion of running operations is achieved. Synchronous Suggests that the operation will run properly with multiple threads of control. When called, the operation will run to completion in one thread. However, other operations can run in other threads at the same time. The class will take care of mutual exclusion issues, so collaboration with other classes is not required. To specify the operation concurrency: 1. Open the operation specification window. 2. Select the Detail tab. 3. Select the desired concurrency from the Concurrency box. Specifying the Operation Preconditions A precondition is some condition that must be true before the operation can run. You can enter any preconditions for the operation on the Preconditions tab of the operation specification window, as shown in Figure 7.12. Chapter 7: Attributes and Operations 282 Figure 7.12: Operation preconditions Preconditions will not affect the code that is generated for the operation. If you have an Interaction diagram that illustrates the operation preconditions, you can enter the Interaction diagram name at the bottom of the Preconditions tab. To specify the operation preconditions: 1. Open the operation specification window. 2. Select the Preconditions tab. 3. Enter the preconditions in the Preconditions field. Specifying the Operation Postconditions Postconditions are conditions that must always be true after the operation has finished executing. Postconditions are entered on the Postconditions tab of the operation specification window, as shown in Figure 7.13. Chapter 7: Attributes and Operations 283 [...]... In UML, these are represented by icons (+, −, and #) for public, private, and protected, and no icon for implementation Rather than using UML notation, you can use Rose notation for attribute and operation visibility The Rose and UML notations for attribute and operation visibility are listed in Table 7.3 Table 7.3: Rose and UML Visibility Notations Rose Notation Visibility Public Private Protected UML. .. check box to set the default option To switch between Rose and UML visibility notations: 1 Select Tools → Options 2 Select the Notation tab 3 Use the Visibility as Icons check box to switch between notations If the check box is selected, Rose notation will be used If the check box is not selected, UML notation will be used Showing Stereotypes In Rose, you can show or hide the stereotypes of your operations... Class diagram with a single line, as shown in Figure 8.1 Figure 8.1: Association relationship When an association connects two classes, as in the above example, each class can send messages to the other in a Sequence or a Collaboration diagram Associations can be bidirectional, as shown above, or unidirectional In UML, bidirectional associations are drawn either with arrowheads on both ends or without arrowheads... shown in Figure 8.8 Figure 8.8: Reuse with unidirectional associations When you generate code for a bidirectional association, Rose will generate attributes in each class In our Flight and Customer example, Rose will place a Flight attribute inside Customer, and a Customer attribute inside Flight Figure 8.9 is an example of the code generated for these two classes 3 05 Chapter 8: Relationships Figure 8.9:... the Semantics field Displaying Attributes and Operations on Class Diagrams UML is very flexible; it allows for either all details to be shown on a Class diagram or only those details you'd like to see In Rose, you can customize your Class diagrams to do the following: • Show all attributes and operations • Hide the attributes • 2 85 Chapter 7: Attributes and Operations Hide the operations • Show selected... altogether Unidirectional associations contain one arrowhead showing the direction of the 301 Chapter 8: Relationships navigation With an association, Rose will place attributes in the classes For example, if there is an association relationship between a Flight class and a Customer class, Rose would place a Customer attribute inside Flight to let the flight know who the passengers are, and a Flight attribute... allows one class to inherit all of the attributes, operations, relationships, and semantics of another modeling element In UML, an inheritance relationship is known as a generalization, and is shown as an arrow from the child class to the parent class, as shown in Figure 8 .5 Figure 8 .5: Generalization relationship Finding Relationships To find relationships, you can examine the model elements you've created... this chapter.) 5 Click OK to close the operation specification window and add the new operation To ensure each message has been mapped to an operation: 1 Select Report → Show Unresolved Messages 2 Rose will display a list of all messages that have not yet been mapped to operations, as shown in Figure 7.19 Figure 7.19: Show Unresolved Messages window Exercise In the exercise for Chapter 5, "Object Interaction,"... One person can be the parent of one or more other people Because there are separate instances of Person with a relationship to each other, we have a reflexive association, as shown in Figure 8.11 Figure 8.11: Reflexive association Using Web Association Stereotypes With the inclusion of web modeling, Rose now supports four stereotypes for associations These are the link, submit, build, and redirect stereotypes... client page It is shown on a class diagram as a unidirectional relationship with a stereotype of : Finally, the redirect stereotype is used to show one page passing processing control to another page A redirect relationship is shown as a unidirectional association with a stereotype of : Creating Associations In Rose, you create associations directly on a Class diagram The Diagram toolbar . operation visibility. The Rose and UML notations for attribute and operation visibility are listed in Table 7.3. Table 7.3: Rose and UML Visibility Notations Rose Notation Visibility UML Notation Public. visibility notation and to Figure 7 .5 to see the same class using Rose visibility notation. To revisit a summary of the possible visibility options, including their Rose and UML notations, see Table 7.2. To. and package. In UML, these are represented by icons (+, −, and #) for public, private, and protected, and no icon for implementation. Rather than using UML notation, you can use Rose notation for

Ngày đăng: 12/08/2014, 21:20

TỪ KHÓA LIÊN QUAN