
- •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 5: Object Interaction
End of a Lifeline
Rose 2001A and 2002 give you greater control over the display of an object's lifeline on a Sequence diagram. Specifically, they give you the ability to position an object at the point at which it is instantiated and the ability to add a destruction marker to indicate when the object is destroyed.
Let's first look at the beginning of the lifeline. As a scenario progresses, objects will be created and destroyed. In Rose 2001A and 2002, you can move an object vertically to indicate where it is created:
You can also indicate when an object is removed from memory. This can be especially helpful in optimizing a design, because it gives you a quick way to see when memory is "cleaned up" in a specific scenario.
The destruction marker is used to indicate the end of a lifeline. It appears as an "X" on the lifeline itself, and the lifeline will not extend beyond it:
To add a lifeline:
1.
Select the Destruction Marker icon from the toolbar.
2.
Click on the object's lifeline, at the point where it is removed from memory.
Working with Scripts
In Rose, notes are typically used to add a comment to an object. Scripts, on the other hand, are usually used to
189

Chapter 5: Object Interaction
add a comment to a message. Scripts are only used on Sequence diagrams. They are usually placed on the left side of the diagram, opposite the message they refer to.
You can use a script to clarify the meaning of a message. You may have a message that reads "Validate User." In the script, you can expand on the meaning: "Validate the ID to be sure that the user exists and that the password is correct."
You can also use scripts to enter some conditional logic in your diagram. Figure 5.19 illustrates some sample scripts in a Sequence diagram.
Figure 5.19: Using scripts in a Sequence diagram
In general, try to avoid putting so much conditional logic on the diagram that the diagram loses its simplicity. By the time you add the details of a nested If statement inside a nested If statement inside a nested If statement, your diagram will probably be cluttered. On the other hand, there are times when you need to show a little bit of conditional logic. Just balance the two extremes. As long as the diagram is easily readable and understandable, you should be fine. If the conditional logic gets too complicated, just create additional Sequence diagrams: one to deal with the if part, one to deal with the else part, and so on.
Besides If statements, you can use scripts to show loops and other pseudocode on your diagram. Scripts won't generate any code, but they will let the developers know how the logic is intended to flow.
To add a script to a Sequence diagram:
1.
Select the Text Box toolbar button.
2.
Click in the location on the diagram where you want the script to reside. Usually this is near the left edge of the diagram.
3.
With the text box selected, type the text of the script.
4.
190
Chapter 5: Object Interaction
Select the text box. Press and hold down Shift and select the message.
5.
Select Edit → Attach Script.
6.
Now, when you move the message up or down in the diagram, the script will move along with it.
To detach a script from a message:
1.
Select the script.
2.
Select Edit → Detach Script.
Switching Between Sequence and Collaboration Diagrams
Typically, you create either a Sequence or a Collaboration diagram for a particular scenario. Without a modeling tool like Rose, it can be too time−consuming to create both, especially because both show you the same information.
In Rose, however, it's very easy to create a Sequence diagram from a Collaboration diagram, or to create a Collaboration diagram from a Sequence diagram. Once you have both a Sequence and a Collaboration diagram for a scenario, it's very easy to switch between the two.
To create a Collaboration diagram from a Sequence diagram:
1.
Open the Sequence diagram.
2.
Select Browse → Create Collaboration diagram, or press F5.
3.
Rose will create a Collaboration diagram with the same name as the open Sequence diagram.
To create a Sequence diagram from a Collaboration diagram:
1.
Open the Collaboration diagram.
2.
Select Browse → Create Sequence diagram, or press F5.
3.
Rose will create a Sequence diagram with the same name as the open Collaboration diagram.
191

Chapter 5: Object Interaction
To switch between Sequence and Collaboration diagrams:
1.
Open the Sequence or Collaboration diagram.
2.
Select Browse → Go to (Sequence or Collaboration) Diagram, or press F5.
3.
Rose will look for a Sequence or Collaboration diagram with the same name as the open diagram.
Two−Pass Approach to Interaction Diagrams
Frequently, people use a two−pass approach to creating Interaction diagrams. On the first pass, they focus on higher−level information that the customers will be concerned with. Messages aren't mapped to operations yet, and objects may not be mapped to classes. These diagrams let just the analysts, customers, and anyone else interested in the business flow see how the logic will flow in the system.
The first pass of a Sequence diagram might look like Figure 5.20.
Figure 5.20: First−pass Sequence diagram
In the second pass, once the customers have agreed to the flow from the first−pass diagram, the team adds more of the detail. The diagram at this point may lose its usefulness to the customer, but will become very useful to the developers, testers, and other members of the project team.
To begin, some additional objects may be added to the diagram. Each Interaction diagram may have a control object, which is responsible for controlling the sequencing through a scenario. All of the Interaction diagrams for a use case may share the same control object, so you have one control object that handles all of the sequencing information for the use case.
If you add a control object, your Sequence diagram will typically look something like Figure 5.21.
192

Chapter 5: Object Interaction
Figure 5.21: Sequence diagram with control object
Notice that the control object doesn't carry out any business processing; it just sends off messages to the other objects. The control object is responsible for coordinating the efforts of the other objects and delegating responsibility. For this reason, control objects are sometimes called manager objects.
The benefit of using a control object is separating the business logic from the sequencing logic. If the sequencing needs to change, only the control object will be affected.
You may also want to add some objects to handle things like security, error handling, or database connectivity. Many of these objects are generic enough to be built once and reused in many applications. Let's take a look at the database issues, for example.
There are two commonly used options when trying to save information to a database or retrieve information from a database. Say we're trying to save a new employee, John Doe, to the database. The John Doe object can either know about the database, in which case it saves itself to the database, or it can be completely separated from the database logic, in which case another object has to handle saving John to the database. Let's start with John knowing about the database, as shown in Figure 5.22.
In this situation, there is no separation of application logic and database logic. The John Doe object takes care of application logic, such as hiring and firing John Doe, as well as database logic, including saving John to the database and retrieving him later. Should the database need to change, the change will ripple through more of the application this way, because many objects will contain some database logic. On the other hand, this approach can be easy to model and implement.
193

Chapter 5: Object Interaction
Figure 5.22: Application logic integrated with database logic
Another option is to separate the application logic from the database logic. In this situation, you will need to create another object to deal with the database logic. We'll call this new object Transaction Manager. The John Doe object will still hold the business logic; it will know how to hire or fire John, or how to give him a raise. The Transaction Manager object will know how to retrieve John from the database or save him to the database. The Sequence diagram might look something like Figure 5.23.
Figure 5.23: Application logic separated from database logic
The advantage of this approach is that now it's easier to reuse the John Doe object in another application with a different database, or with no database at all. It also helps minimize the impact of a requirement change. Database changes won't affect the application logic, and application changes won't affect the database logic. The disadvantage here can be that you'll need a little more time to model and implement this solution.
These are two of the more common approaches, although there are some other approaches you can take when dealing with database issues. Whichever decision you make, be sure to keep the approach consistent across Interaction diagrams.
Aside from database issues, you may add objects now for things like error handling, security, or interprocess communication. These details won't interest the customer, but will be critical for the developers.
194