- •Table of Contents
- •Mastering UML with Rational Rose 2002
- •Chapter 1: Introduction to UML
- •Encapsulation
- •Inheritance
- •Polymorphism
- •What Is Visual Modeling?
- •Systems of Graphical Notation
- •Booch Notation
- •Object Management Technology (OMT)
- •Unified Modeling Language (UML)
- •Understanding UML Diagrams
- •Business Use Case Diagrams
- •Use Case Diagrams
- •Activity Diagrams
- •Sequence Diagrams
- •Collaboration Diagrams
- •Class Diagrams
- •Statechart Diagrams
- •Component Diagrams
- •Deployment Diagrams
- •Visual Modeling and the Software Development Process
- •Inception
- •Elaboration
- •Construction
- •Transition
- •Summary
- •Chapter 2: A Tour of Rose
- •What Is Rose?
- •Getting Around in Rose
- •Parts of the Screen
- •Exploring Four Views in a Rose Model
- •Use Case View
- •Logical View
- •Component View
- •Deployment View
- •Working with Rose
- •Creating Models
- •Saving Models
- •Exporting and Importing Models
- •Publishing Models to the Web
- •Working with Controlled Units
- •Using the Model Integrator
- •Working with Notes
- •Working with Packages
- •Adding Files and URLs to Rose Model Elements
- •Adding and Deleting Diagrams
- •Setting Global Options
- •Working with Fonts
- •Working with Colors
- •Summary
- •Chapter 3: Business Modeling
- •Introduction to Business Modeling
- •Why Model the Business?
- •Do I Need to Do Business Modeling?
- •Business Modeling in an Iterative Process
- •Business Actors
- •Business Workers
- •Business Use Cases
- •Business Use Case Diagrams
- •Activity Diagrams
- •Business Entities
- •Organization Unit
- •Where Do I Start?
- •Identifying the Business Actors
- •Identifying the Business Workers
- •Identifying the Business Use Cases
- •Showing the Interactions
- •Documenting the Details
- •Creating Business Use Case Diagrams
- •Deleting Business Use Case Diagrams
- •The Use Case Diagram Toolbar
- •Adding Business Use Cases
- •Business Use Case Specifications
- •Assigning a Priority to a Business Use Case
- •Viewing Diagrams for a Business Use Case
- •Viewing Relationships for a Business Use Case
- •Working with Business Actors
- •Adding Business Actors
- •Adding Actor Specifications
- •Assigning an Actor Stereotype
- •Setting Business Actor Multiplicity
- •Viewing Relationships for a Business Actor
- •Working with Relationships
- •Association Relationship
- •Generalization Relationship
- •Working with Organization Units
- •Adding Organization Units
- •Deleting Organization Units
- •Activity Diagrams
- •Adding an Activity Diagram
- •Adding Details to an Activity Diagram
- •Summary
- •Chapter 4: Use Cases and Actors
- •Use Case Modeling Concepts
- •Actors
- •Use Cases
- •Traceability
- •Flow of Events
- •Relationships
- •Use Case Diagrams
- •Activity Diagrams
- •Activity
- •Start and End States
- •Objects and Object Flows
- •Transitions
- •Synchronization
- •Working with Use Cases in Rational Rose
- •The Use Case Diagram Toolbar
- •Creating Use Case Diagrams
- •Deleting Use Case Diagrams
- •Adding Use Cases
- •Deleting Use Cases
- •Use Case Specifications
- •Naming a Use Case
- •Viewing Participants of a Use Case
- •Assigning a Use Case Stereotype
- •Assigning a Priority to a Use Case
- •Creating an Abstract Use Case
- •Viewing Diagrams for a Use Case
- •Viewing Relationships for a Use Case
- •Working with Actors
- •Adding Actors
- •Deleting Actors
- •Actor Specifications
- •Naming Actors
- •Assigning an Actor Stereotype
- •Setting Actor Multiplicity
- •Creating an Abstract Actor
- •Viewing Relationships for an Actor
- •Viewing an Actor's Instances
- •Working with Relationships
- •Association Relationship
- •Includes Relationship
- •Extends Relationship
- •Generalization Relationship
- •Working with Activity Diagrams
- •The Activity Diagram Toolbar
- •Creating Activity Diagrams
- •Deleting Activity Diagrams
- •Exercise
- •Problem Statement
- •Create a Use Case Diagram
- •Summary
- •Chapter 5: Object Interaction
- •Interaction Diagrams
- •What Is an Object?
- •What Is a Class?
- •Where Do I Start?
- •Finding Objects
- •Finding the Actor
- •Using Interaction Diagrams
- •Sequence Diagrams
- •The Sequence Diagram Toolbar
- •Collaboration Diagrams
- •The Collaboration Diagram Toolbar
- •Working with Actors on an Interaction Diagram
- •Working with Objects
- •Adding Objects to an Interaction Diagram
- •Deleting Objects from an Interaction Diagram
- •Setting Object Specifications
- •Naming an Object
- •Mapping an Object to a Class
- •Setting Object Persistence
- •Using Multiple Instances of an Object
- •Working with Messages
- •Adding Messages to an Interaction Diagram
- •Adding Messages to a Sequence Diagram
- •Deleting Messages from a Sequence Diagram
- •Reordering Messages in a Sequence Diagram
- •Message Numbering in a Sequence Diagram
- •Viewing the Focus of Control in a Sequence Diagram
- •Adding Messages to a Collaboration Diagram
- •Deleting Messages from a Collaboration Diagram
- •Message Numbering in a Collaboration Diagram
- •Adding Data Flows to a Collaboration Diagram
- •Setting Message Specifications
- •Naming a Message
- •Mapping a Message to an Operation
- •Setting Message Synchronization Options
- •Setting Message Frequency
- •End of a Lifeline
- •Working with Scripts
- •Switching Between Sequence and Collaboration Diagrams
- •Exercise
- •Problem Statement
- •Create Interaction Diagrams
- •Summary
- •Chapter 6: Classes and Packages
- •Logical View of a Rose Model
- •Class Diagrams
- •What Is a Class?
- •Finding Classes
- •Creating Class Diagrams
- •Deleting Class Diagrams
- •Organizing Items on a Class Diagram
- •Using the Class Diagram Toolbar
- •Working with Classes
- •Adding Classes
- •Class Stereotypes
- •Analysis Stereotypes
- •Class Types
- •Interfaces
- •Web Modeling Stereotypes
- •Other Language Stereotypes
- •Class Specifications
- •Naming a Class
- •Setting Class Visibility
- •Setting Class Multiplicity
- •Setting Storage Requirements for a Class
- •Setting Class Persistence
- •Setting Class Concurrency
- •Creating an Abstract Class
- •Viewing Class Attributes
- •Viewing Class Operations
- •Viewing Class Relationships
- •Using Nested Classes
- •Viewing the Interaction Diagrams That Contain a Class
- •Setting Java Class Specifications
- •Setting CORBA Class Specifications
- •Working with Packages
- •Adding Packages
- •Deleting Packages
- •Exercise
- •Problem Statement
- •Creating a Class Diagram
- •Summary
- •Chapter 7: Attributes and Operations
- •Working with Attributes
- •Finding Attributes
- •Adding Attributes
- •Deleting Attributes
- •Setting Attribute Specifications
- •Setting the Attribute Containment
- •Making an Attribute Static
- •Specifying a Derived Attribute
- •Working with Operations
- •Finding Operations
- •Adding Operations
- •Deleting Operations
- •Setting Operation Specifications
- •Adding Arguments to an Operation
- •Specifying the Operation Protocol
- •Specifying the Operation Qualifications
- •Specifying the Operation Exceptions
- •Specifying the Operation Size
- •Specifying the Operation Time
- •Specifying the Operation Concurrency
- •Specifying the Operation Preconditions
- •Specifying the Operation Postconditions
- •Specifying the Operation Semantics
- •Displaying Attributes and Operations on Class Diagrams
- •Showing Attributes
- •Showing Operations
- •Showing Visibility
- •Showing Stereotypes
- •Mapping Operations to Messages
- •Mapping an Operation to a Message on an Interaction Diagram
- •Exercise
- •Problem Statement
- •Add Attributes and Operations
- •Summary
- •Chapter 8: Relationships
- •Relationships
- •Types of Relationships
- •Finding Relationships
- •Associations
- •Using Web Association Stereotypes
- •Creating Associations
- •Deleting Associations
- •Dependencies
- •Creating Dependencies
- •Deleting Dependencies
- •Package Dependencies
- •Creating Package Dependencies
- •Deleting Package Dependencies
- •Aggregations
- •Creating Aggregations
- •Deleting Aggregations
- •Generalizations
- •Creating Generalizations
- •Deleting Generalizations
- •Working with Relationships
- •Setting Multiplicity
- •Using Relationship Names
- •Using Stereotypes
- •Using Roles
- •Setting Export Control
- •Using Static Relationships
- •Using Friend Relationships
- •Setting Containment
- •Using Qualifiers
- •Using Link Elements
- •Using Constraints
- •Exercise
- •Problem Statement
- •Adding Relationships
- •Summary
- •Chapter 9: Object Behavior
- •Statechart Diagrams
- •Creating a Statechart Diagram
- •Adding States
- •Adding State Details
- •Adding Transitions
- •Adding Transition Details
- •Adding Special States
- •Using Nested States and State History
- •Exercise
- •Problem Statement
- •Create a Statechart Diagram
- •Summary
- •Chapter 10: Component View
- •What Is a Component?
- •Types of Components
- •Component Diagrams
- •Creating Component Diagrams
- •Adding Components
- •Adding Component Details
- •Adding Component Dependencies
- •Exercise
- •Problem Statement
- •Summary
- •Chapter 11: Deployment View
- •Deployment Diagrams
- •Opening the Deployment Diagram
- •Adding Processors
- •Adding Processor Details
- •Adding Devices
- •Adding Device Details
- •Adding Connections
- •Adding Connection Details
- •Adding Processes
- •Exercise
- •Problem Statement
- •Create Deployment Diagram
- •Summary
- •Chapter 12: Introduction to Code Generation and Reverse Engineering Using Rational Rose
- •Preparing for Code Generation
- •Step One: Check the Model
- •Step Two: Create Components
- •Step Three: Map Classes to Components
- •Step Five: Select a Class, Component, or Package
- •Step Six: Generate Code
- •What Gets Generated?
- •Introduction to Reverse Engineering Using Rational Rose
- •Model Elements Created During Reverse Engineering
- •Summary
- •Chapter 13: ANSI C++ and Visual C++ Code Generation and Reverse Engineering
- •Generating Code in ANSI C++ and Visual C++
- •Converting a C++ Model to an ANSI C++ Model
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Package (Class Category) Properties
- •Component (Module Specification) Properties
- •Role Properties
- •Generalization Properties
- •Class Model Assistant
- •Component Properties
- •Project Properties
- •Visual C++ and ATL Objects
- •Generated Code
- •Code Generated for Classes
- •Code Generated for Attributes
- •Code Generated for Operations
- •Visual C++ Code Generation
- •Reverse Engineering ANSI C++
- •Reverse Engineering Visual C++
- •Summary
- •Overview
- •Introduction to Rose J
- •Beginning a Java Project
- •Selecting a Java Framework
- •Linking to IBM VisualAge for Java
- •Linking to Microsoft Visual J++
- •Project Properties
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Module Properties
- •Role Properties
- •Generating Code
- •Generated Code
- •Classes
- •Attributes
- •Operations
- •Bidirectional Associations
- •Unidirectional Associations
- •Associations with a Multiplicity of One to Many
- •Associations with a Multiplicity of Many to Many
- •Reflexive Associations
- •Aggregations
- •Dependency Relationships
- •Generalization Relationships
- •Interfaces
- •Java Beans
- •Support for J2EE
- •EJBs
- •Servlets
- •JAR and WAR Files
- •Automated J2EE Deployment
- •Reverse Engineering
- •Summary
- •Starting a Visual Basic Project
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Module Specification Properties
- •Role Properties
- •Generalization Properties
- •Generated Code
- •Classes
- •Attributes
- •Operations
- •Bidirectional Associations
- •Unidirectional Associations
- •Associations with a Multiplicity of One to Many
- •Associations with a Multiplicity of Many to Many
- •Reflexive Associations
- •Aggregations
- •Dependency Relationships
- •Generalization Relationships
- •Reverse Engineering
- •Summary
- •Overview
- •Introduction to XML DTD
- •Elements
- •Attributes
- •Entities and Notations
- •Project Properties
- •Class Properties
- •Attribute Properties
- •Role Properties
- •Component Properties
- •Generating Code
- •Generated Code
- •Classes
- •Attributes
- •Reverse Engineering DTD
- •Summary
- •Project Properties
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Module Properties
- •Association (Role) Properties
- •Dependency Properties
- •Generated Code
- •Classes
- •Attributes
- •Operations
- •Bidirectional Associations
- •Unidirectional Associations
- •Associations with a Multiplicity of One to Many
- •Associations with a Multiplicity of Many to Many
- •Associations with Bounded Multiplicity
- •Reflexive Associations
- •Aggregations
- •Dependency Relationships
- •Generalization Relationships
- •Reverse Engineering CORBA Source Code
- •Summary
- •Chapter 18: Rose Data Modeler
- •Object Models and Data Models
- •Creating a Data Model
- •Logic in a Data Model
- •Adding a Database
- •Adding Tablespaces
- •Adding a Schema
- •Creating a Data Model Diagram
- •Creating Domain Packages and Domains
- •Adding Tables
- •Adding Columns
- •Setting a Primary Key
- •Adding Constraints
- •Adding Triggers
- •Adding Indexes
- •Adding Stored Procedures
- •Adding Relationships
- •Adding Referential Integrity Rules
- •Working with Views
- •Generating an Object Model from a Data Model
- •Generating a Data Model from an Object Model
- •Generating a Database from a Data Model
- •Updating an Existing Database
- •Reverse Engineering a Database
- •Summary
- •Chapter 19: Web Modeling
- •Modeling a Web Application
- •Web Class Stereotypes
- •Relationships
- •Reverse Engineering a Web Application
- •Generating Code for a Web Application
- •Summary
- •Appendix: Getting Started with UML
- •Building a Business Use Case Diagram
- •Building a Workflow (Activity) Diagram
- •Building a Use Case Diagram
- •Building an Interaction Diagram
- •Building a Class Diagram
- •Web Modeling
- •Adding Class Relationships
- •Building a Statechart Diagram
- •Building a Component Diagram
- •Building a Deployment Diagram
Chapter 7: Attributes and Operations
OR
1.
Right−click the attribute in the browser.
2.
Select Open Specification from the shortcut menu.
3.
Enter the attribute documentation in the Documentation area of the class attribute specification window.
OR
1.
Open the class specification window for the attribute's class.
2.
Select the Attributes tab.
3.
Select the attribute.
4.
Type the attribute documentation in the documentation window.
Deleting Attributes
At times, you may find that you need to delete an attribute you have created. This is most common when the system requirements change, removing the need for a particular attribute. In Rose, the quickest way to delete an attribute is typically through the browser. However, you can also use a Class diagram to delete an attribute. When an attribute is deleted from one Class diagram, Rose will automatically remove it from the model, including any other Class diagrams on which it appeared.
To delete an attribute from a class:
1.
Right−click the attribute in the browser.
2.
Select Delete from the shortcut menu.
OR
1.
Select the attribute on a Class diagram.
2.
Use the Backspace key to erase the attribute name, data type, and initial value from the diagram.
3.
255
Chapter 7: Attributes and Operations
Single−click anywhere on the diagram.
4.
Rose will confirm the deletion before the attribute is removed.
OR
1.
Open the class specification window for the attribute's class.
2.
Select the Attributes tab.
3.
Right−click the attribute you want to delete.
4.
Select Delete from the shortcut menu.
5.
Rose will confirm the deletion before the attribute is removed.
Setting Attribute Specifications
As with other Rose model elements, there are a number of detailed specifications you can add to an attribute. These include, among other things, the attribute data type, initial value, stereotype, and visibility. In the next several sections, we'll take a look at each specification.
All of the specifications are viewed or changed on the attribute specification window, as shown in Figure 7.2.
256
Chapter 7: Attributes and Operations
Figure 7.2: Attribute specification window
To open the attribute specifications:
1.
Right−click the attribute in the browser.
2.
Select Open Specification from the shortcut menu.
OR
1.
Open the class specification window for the attribute's class.
2.
Select the Attributes tab.
3.
Double−click the appropriate attribute.
Note In the following sections, if you are working with a Java, COM, or CORBA class, the specification window will be different. To open the standard specifications, right−click and select Open Standard Specification from the shortcut menu.
Setting the Attribute Data Type
One of the main pieces of information you specify about an attribute is its data type. The data type is the language−specific type, such as string, integer, long, or Boolean. Before you can generate code, you must enter a data type for each attribute.
257
Chapter 7: Attributes and Operations
When you are entering the data type, you can either use built−in data types (string, integer, long, etc.) for your programming language or the names of classes that you have defined in your Rose model. To see the classes you have defined in the drop−down list box, select the Show Classes check box.
To set the attribute data type:
1.
Right−click the attribute in the browser.
2.
Select Open Specification from the shortcut menu. Rose will open the class attribute specification window.
3.
Select a data type from the Type drop−down list box or enter a new data type.
OR
1.
Select the attribute on a Class diagram.
2.
Type a colon and the data type after the attribute name. For example, if you have an attribute called Address that you want to set as a string, type Address : String.
Setting the Attribute Stereotype
Like actors, use cases, and classes, attributes can be stereotyped. An attribute stereotype is a way to classify the attribute. For example, you may have some attributes that map to fields in your database, and other attributes that do not. You can define two stereotypes, one for each of these types of attributes.
In Rose, you are not required to assign stereotypes to attributes. You can generate code without using attribute stereotypes. Stereotypes can, however, improve the readability and comprehensibility of your model.
To set the attribute stereotype:
1.
Right−click the attribute in the browser.
2.
Select Open Specification from the shortcut menu. Rose will open the Class Attribute Specification window.
3.
Select a stereotype from the drop−down list box or enter a new stereotype.
OR
1.
Select the attribute in the browser.
2.
258
Chapter 7: Attributes and Operations
Single−click the attribute again to edit the name. Before the name, the double angle bracket characters (<< >>) will appear:
3.
Type the stereotype between the double angle brackets:
Setting the Attribute Initial Value
Many attributes will have some sort of a default value associated with them. For example, you may have a class called Order, which holds information and behavior about purchase orders for your company. The Order class may have an attribute called TaxRate for the sales tax rate of the purchase. In your city, for example the tax rate may be 7.5%, so most of your orders would be at the 7.5% rate. You can assign an initial value of
.075 to the TaxRate attribute.
Like attribute stereotypes, initial values aren't required in order to generate code. However, if an initial value is present, Rose will generate the code necessary to initialize the attribute.
To set the attribute initial value:
1.
Right−click the attribute in the browser.
2.
Select Open Specification from the shortcut menu. The class attribute specification window will appear.
3.
In the Initial Value field, enter the attribute's default value.
OR
1.
Select the attribute on a Class diagram.
2.
After the attribute data type, enter an equals sign (=), followed by the default value. For example, if you have an integer attribute called EmployeeID and you wish to set its default value to 0, your Class
259
Chapter 7: Attributes and Operations
diagram would look like this:
Setting the Attribute Visibility
One of the central concepts of object−oriented programming is that of encapsulation. Each class, by having attributes and operations, encapsulates a little bit of information and a little bit of behavior. One of the benefits of this approach is the ability to have small, self−contained pieces of code. The Employee class, for example, has all of the information and behavior related to an employee.
You can view a class like this:
The private attributes are contained inside the class, hidden away from other classes. Because the attributes are encapsulated within a class, you will need to define which classes have access to view and change the attribute. This is known as the attribute visibility.
There are four visibility options for an attribute. Let's look at each in the context of an example: We have an Employee class with an attribute called Address, and a Company class.
Public Suggests that the attribute is visible to all other classes. Any other class can view or modify the value of the attribute. In this case, the Company class could view or modify the value of the Address attribute of the Employee class. The UML notation for a public attribute is a plus sign (+).
Private Means that the attribute is not visible to any other class. The Employee class would know what the value of the Address attribute is, and would be able to change the value, but the Company class wouldn't be able to view or edit the Address attribute. If the Company class needed to view or edit Address, it would have to ask the Employee class to view or edit the attribute. This is typically done through public operations. We'll talk more about this in the operations part of this chapter. The UML notation for a private attribute is a minus sign (−).
Protected Suggests that the class and any of its descendants have access to the attribute. In our example, assume we have two different types of employees, hourly employees and salaried employees. The classes
260
Chapter 7: Attributes and Operations
HourlyEmp and SalariedEmp are inherited from the Employee class. If the Address attribute has protected visibility, it can be viewed or changed by the Employee class, the HourlyEmp class, or the SalariedEmp class, but not by the Company class. The UML notation for a protected attribute is a pound sign (#).
Package or implementation Indicates that the attribute is public, but only to classes in the same package. In our example, assume the Address attribute of the Employee class has package visibility. Address could be modified by Company only if Company and Employee are in the same package. With implementation visibility, no icon appears next to the attribute.
In general, private or protected visibility is recommended for attributes. Using these options helps you maintain better control of your code and the attribute. By using private or protected attributes, you won't have a situation where an attribute is being modified by all sorts of classes throughout the system. Instead, the logic for modifying an attribute is encapsulated in a single class, along with the attribute. The visibility options you select will affect the generated code. For example, Figure 7.3 is the Java code generated for the class in the previous example.
261
Chapter 7: Attributes and Operations
Figure 7.3: Attribute visibility in generated code
Rose supports two sets of visibility notations. The first is UML notation (+, −, #) for public, private, and protected attributes, respectively. The second notation includes four Rose icons, as shown in Table 7.1.
Table 7.1: Rose Visibility Icons
Icon Description
Public
Private
Protected
Package or implementation
On a Class diagram, you can use either of these notations. See the upcoming numbered steps for a description of how to switch between these two notations. Figure 7.4 shows an example of a class using UML visibility notation. Figure 7.5 shows the same class using Rose visibility notation. Rose and UML visibility notations are summarized in Table 7.2.
262
Chapter 7: Attributes and Operations
Figure 7.4: UML visibility notation
Figure 7.5: Rose visibility notation
Table 7.2: Rose and UML Visibility Notations
Rose Notation |
If you want to… |
Use… |
UML Notation |
|
Make an attribute visible to all |
Public visibility |
+ |
|
classes |
|
|
|
Make an attribute visible to only one |
Private visibility |
− |
|
class |
|
|
|
Make an attribute visible to a class |
Protected visibility |
# |
|
and its descendants |
|
|
|
Make an attribute visible to all |
Package or implementation visibility |
<no icon> |
|
classes in the same pacakage |
|
|
To set the attribute visibility: |
|
|
|
1. |
|
|
|
Right−click the attribute in the browser. |
|
|
2.
Select Open Specification from the shortcut menu. The class attribute specification window will appear.
3.
In the Export Control field, select the attribute's visibility: Public, Protected, Private, or Implementation. By default, all attributes have private visibility.
OR
1.
Select the attribute on a Class diagram.
2.
If you are using UML notation for visibility, single−click the icon (+, −, or #) next to the attribute. Select a visibility option from the list of Rose visibility icons that appears.
3.
263