- •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
In the previous chapter, we looked at classes and packages. Remember that classes are encapsulated attributes (data) and the operations (behaviors) that act on those attributes. Now we will discuss working with attributes and operations. We will begin by talking about how to find attributes, add them to the Rose model, and add details about the attributes. We will then look at finding operations, adding them to the model, and adding details to the operations. Next, we will look at displaying attributes and operations on Class diagrams. Lastly, we will discuss how to map operations to messages on Interaction diagrams.
Working with Attributes
An attribute is a piece of information associated with a class. For example, a Company class might have attributes called Name, Address, and NumberOfEmployees. A Ticket class might have attributes called FlightNumber, Cost, and PassengerName.
In Rose, you may add one or more attributes to each of the classes in the model. The following sections describe how to find attributes, add them to the model, delete them from the model, and set the detailed specifications for each attribute.
Finding Attributes
There are many sources of attributes. To begin, you can take your use case documentation and look for nouns in your flow of events. Some of the nouns will be objects or classes, some will be actors, and others will be attributes. For example, your flow of events may read "The user enters the employee's name, address, social security number, and phone number," letting you know that the Employee class has attributes called Name, Address, SSN, and Phone. In our airline example, the user is looking for a flight and enters a departure and destination city as well as a departure date. From this, we know that a Flight class would have attributes called DepartureCity, DestinationCity, and DepartureDate.
Another good place to look is the requirements document. There may be requirements that outline what information should be collected by the system. Any piece of information that is collected should be an attribute in a class.
Finally, you can check the database structure. If your database structure has already been defined, the fields in the tables will give you a good idea of what your attributes are. Frequently, there's a one−to−one mapping between database tables and entity classes. Going back to our previous example, a Flight table may have fields called DepartureCity, DestinationCity, and DepartureDate. The corresponding class, called Flight, will have attributes called DepartureCity, DestinationCity, and DepartureDate. It's important to note that there isn't always a one−to−one mapping between the database tables and the classes. There are different considerations when designing your database and designing your classes. Relational databases, for example, don't directly support inheritance.
However, when you identify attributes, be sure that each one can be traced back to a requirement. This can help solve the classic problem of an application capturing a great deal of information that nobody uses. Each requirement should be traced back to the flow of events of a use case, to a particular requirement, or to an existing database table. If you cannot trace the requirement, you cannot be sure that it is needed by the customer. This can be a bit of a deviation from some older methodologies—rather than create the database structure first and then wrap the system around it, you're building the system and the database at the same time to conform to the same requirements.
251
Chapter 7: Attributes and Operations
As you identify attributes, carefully assign them to the appropriate classes. An attribute should be a piece of information related to the class. For example, an Employee class might have name and address information, but shouldn't include information about the products the employee's company manufactures. A Product class would be a better place to store information about products.
Be cautious of classes with too many attributes. If you find that a particular class has a large number of attributes, it might be an indication that the class should be split into two smaller classes. If you have a class with more than about 10 or 15 attributes, be sure to take a close look at it. The class may be perfectly legitimate; just be sure that all of the attributes are needed and truly belong to that class. Similarly, be cautious of classes with too few attributes. Again, it may be perfectly legitimate. Control classes, for example, tend to have very few attributes. However, it may also be a sign that two or more classes should be combined. If you have a class with only one or two attributes, it may be worth a closer look.
Sometimes you may run into a piece of information and wonder whether it's an attribute or a class. For example, let's look at an attribute like Company Name. The question you face might be: Is the company name an attribute of a Person class, or should Company be its own class? The answer really depends on the application you are writing. If you need to keep information about the company and there is some behavior associated with a company, it may be its own class. For example, you may be building a system to keep track of your customers. In this case, you'll want to keep some information about the companies you sell products or services to. You may want to know how many employees the company has, the company's name and address, the name of your contact with the company, and so on.
On the other hand, you may not need to know specific information about the company. You may be writing an application that will generate letters to your contacts in other organizations. When generating the letters, you will need to know a company name. However, you don't need to know any more information about the company. In this case, you could consider the company name to be an attribute of a Contact class.
Another thing to consider is whether the piece of information in question has behavior. If the Company has some behavior in your application, it is better modeled as a class. If the company has no behavior, it may be better modeled as an attribute.
Once you've identified the attributes, the next step is to add them to your Rose model. In the following sections, we'll discuss how to add attributes and add details to the attributes, such as the data type and default value.
Adding Attributes
As you identify attributes, you can add them to the appropriate class in your Rose model. There are three main pieces of information you can supply for each attribute: the attribute name, the data type, and the initial value. Before you can generate code for your model, you must supply a name and data type for each attribute. Initial values are optional.
There are three ways to add an attribute. You may type the attribute directly onto a Class diagram, add the attribute using the browser, or add the attribute using the class specification window.
Once you've added an attribute, you can add documentation for it. Typically, attribute documentation would include a short description or definition of the attribute. Any attribute documentation will be included as a comment in the code generated from the model. By documenting the attributes as you go along, you are beginning to document the code as well.
To add an attribute to a class:
1. |
252 |
Chapter 7: Attributes and Operations
Right−click the class on a Class diagram.
2.
Select New → Attribute.
3.
Type the attribute name, using the format Name : Data Type = Initial Value. For example:
Address : String
IDNumber : Integer = 0
The data type is required in order to generate code, but the initial value is optional.
4.
To add more attributes, press Enter and type the new attributes directly on the Class diagram.
OR
1.
Right−click the class in the browser.
2.
Select New → Attribute.
3.
A new attribute, called "name" by default, will appear under the class in the browser. Type the name of the new attribute. Attribute data types and default values cannot be assigned in the browser; you can enter them on the Class diagram, as we'll discuss shortly.
OR
1.
Open the class specification window for the attribute's class.
2.
Select the Attributes tab. If the class already has some attributes, they will be listed here.
3.
Right−click anywhere inside the Attributes area, as in Figure 7.1.
253
Chapter 7: Attributes and Operations
Figure 7.1: Adding a new attribute in the class specification window
4.
Select Insert from the shortcut menu.
5.
Type the name of the new attribute.
6.
Enter the visibility, stereotype, data type, and initial value in the appropriate columns. We'll discuss each of these in detail in the following sections.
To add documentation to an attribute:
1.
Select the attribute in the browser.
2.
Type the attribute documentation in the documentation window.
OR
1.
Select the attribute on a Class diagram.
2.
Type the attribute documentation in the documentation window.
254