- •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
In this chapter, we will discuss how to model the interactions between the objects in the system. The two types of Interaction diagrams we'll take a look at in this chapter are Sequence diagrams and Collaboration diagrams. Both show the objects participating in a flow through a use case and the messages that are sent between the objects. Sequence diagrams are ordered by time; Collaboration diagrams are organized around the objects themselves.
In the exercise at the end of the chapter, we will build a sample Sequence diagram.
∙
Looking at Sequence and Collaboration diagrams
∙
Adding objects to Sequence and Collaboration diagrams
∙
Using messages with Sequence and Collaboration diagrams
∙
Switching between Sequence and Collaboration diagrams
∙
Using the two−pass approach to create Interaction diagrams
Interaction Diagrams
An Interaction diagram shows you, step−by−step, one of the flows through a use case: what objects are needed for the flow, what messages the objects send to each other, what actor initiates the flow, and what order the messages are sent. In our airline example, we have several alternate flows through the "Purchase
Ticket" use case. Therefore, we will have several Interaction diagrams for this use case. We'll have the "happy day" Interaction diagram, which shows what happens when all goes well. And we'll have additional diagrams showing what happens with the alternate flows, such as what happens when someone requests a
frequent−flyer ticket, what happens when someone's credit card is denied, and so on. All of the different scenarios that our system will need to implement are documented in an Interaction diagram.
The two types of Interaction diagrams we'll talk about are Sequence diagrams and Collaboration diagrams. A Sequence diagram is ordered by time. Figure 5.1 is an example of a Sequence diagram.
159
Chapter 5: Object Interaction
Figure 5.1: Sequence diagram
A Collaboration diagram shows the same information, but is organized differently. Figure 5.2 is an example of a Collaboration diagram.
Figure 5.2: Collaboration diagram
Although a Sequence diagram and a Collaboration diagram show you the same information, there are a couple of differences between these two diagrams. Sequence diagrams can show a focus of control; Collaboration diagrams can show a data flow. We'll talk about these differences when discussing messages below.
Interaction diagrams contain a lot of the same detail that is spelled out in the flow of events, but here the information is presented in a way that is more useful to the developers. While the flow of events focuses on what the system needs to do, Sequence and Collaboration diagrams help to define how the system will do it. These diagrams focus on the objects that will be created to implement the functionality spelled out in the use cases. Sequence and Collaboration diagrams can show objects, classes, or both.
Before we get into the details of Sequence and Collaboration diagrams, let's review the concept of an object and a class. If you are familiar with object−oriented concepts, skip to the section titled "Where Do I Start?"
160
Chapter 5: Object Interaction
What Is an Object?
We see objects all around us. The chair you're sitting in, the book you're reading, and the lightbulb that's helping you see are all examples of objects in the real world. An object in the software world is very much the same.
An object is something that encapsulates information and behavior. It's a term that represents some concrete, real−world thing. Examples of objects are:
∙
Flight #1020
∙
The house at 7638 Main Street
∙
The yellow flower just outside my kitchen window
In the airline example, some of the objects would include an airplane, a flight, a passenger, a piece of luggage, or a ticket.
Every object encapsulates some information and some behavior. There might be a flight #1020 object, for example, that has some information: The departure date is May 24, the departure time is 9:40 p.m., the flight number is 1020, and the departure city is Los Angeles. The flight object also has some behavior: It knows how to add a passenger to the flight, remove a passenger from the flight, and determine when it is full.
The pieces of information held by an object are known as its attributes. Although the values of the attributes will change over time (flight 1020 will have a departure date of May 25 the next day), the attributes themselves will not change. Flight 1020 will always have a departure date, a departure time, a flight number, and a departure city.
The behaviors an object has are known as its operations. In this case, the operations for the flight include adding a passenger, removing a passenger, and checking to see when the flight is full. In Rose, objects are added to the Interaction diagrams. When dragging an actor (which in Rose is a class stereotype) or some other class onto an Interaction diagram, an object instantiation of that class will automatically be created. Removing an object from a diagram in Rose will not delete the class from the model.
What Is a Class?
A class is something that provides a blueprint for an object. In other words, a class defines what information an object can hold and what behavior it can have. For example, classes for flight #1020, the house at 7638 Main Street, and the yellow flower just outside my kitchen window would be: Flight, House, and Flower. The House class would just specify that a house has a height, width, number of rooms, and square footage. The House at 7638 Main Street object might have a height of 40 feet, a width of 60 feet, 10 rooms, and 2000 square feet. A class is a more generic term that simply provides a template for objects.
161
Chapter 5: Object Interaction
Think of a class as a blueprint for a house, and the objects as the 25 houses that were all built from that blueprint. We'll talk more about classes in the next chapter.
Where Do I Start?
To create a Sequence or Collaboration diagram, we first go through the flow of events and determine how many of the flows will need an Interaction diagram. You can create a diagram for just the primary flow or for all the alternate flows and error flows as well. If two alternate or error flows are very similar, they may be combined onto one diagram. The more diagrams you create, the more thorough your exploration of how the system should be built and the easier the rest of the steps in the process will be. (Class diagrams, Component diagrams, and Deployment diagrams will be covered in the coming chapters.) The trade−off, of course, is time. It can take quite some time to build a detailed Sequence or Collaboration diagram, because great many design decisions need to be made at this point.
Patterns can come to the rescue here. You can build patterns for common logic. They include things such as retrieving data from the database, checking the user's security level, error handling and logging, interprocess communication, and so on. If you document these patterns in their own Sequence diagrams, it isn't necessary for every diagram to show how you check the user's security level; you can simply reference the security pattern. These types of patterns are also excellent candidates for reuse in other projects.
The steps involved in creating a Sequence or Collaboration diagram are:
∙
Find the objects.
∙
Find the actor.
∙
Add messages to the diagram.
We will discuss each of these steps in the next sections.
Finding Objects
A good way to find some initial objects is to examine the nouns in your flow of events. Another good place to look is in the scenario documents. A scenario is a specific instance of a flow of events. The flow of events for the "Purchase Ticket" use case has several scenarios. For example, John Doe purchases a ticket for flight #1020; John requests and gets a frequent−flyer ticket for flight #1020; John requests a frequent−flyer ticket for flight #1020, but there are no seats available; John requests a frequent−flyer ticket for flight #1020, but he does not have enough frequent−flyer miles. More scenarios would be developed to explain exceptions, such as what happens if there's a problem with the credit card, if John is already booked for flight #1020, or if the credit system can't be accessed. Any exceptions like these that should be programmed into the system should
162