Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Appendix: Getting Started with UML

Follow these steps to add COM objects to the model:

1.

Select the COM Object class button from the toolbar.

2.

Click in the diagram to add the class.

3.

Name the class.

A COM object is an object such as an ActiveX control that uses Microsoft's Component Object Model.

Adding Class Relationships

There are many different types of relationships between classes. An association relationship indicates that one class needs to communicate with another. Associations may be unidirectional or bidirectional. An aggregation relationship suggests a whole/part relationship between two classes. A generalization relationship indicates a parent/child inheritance relationship between two classes. Finally, a dependency relationship is a weaker form of association, suggesting that a change to one class may affect another.

Association names can be added to a relationship to clarify the relationship's purpose. Role names can also be used that show what role each class plays in the relationship. Multiplicity settings show how many instances of one object are related to a single instance of the other object.

Relationships are drawn on Class diagrams as arrows between the two related classes. Different types of arrows are used to indicate different types of relationships.

Follow these steps to add association relationships between the classes:

1.

Select the Unidirectional Association or the Bidirectional Association toolbar button.

2.

Drag an arrow from one class to the other.

3.

Type an association name, if needed.

An association relationship is a semantic connection between classes. It indicates that one class needs to communicate with another (for example, one class needs to send a message to the other). Unidirectional associations suggest that the messages can be sent in only one direction, while bidirectional associations suggest that messages can be sent in both directions (i.e., each class can call a method of the other).

694

Appendix: Getting Started with UML

To add aggregation relationships:

1.

Select the Aggregation toolbar button.

2.

Drag an arrow from the "whole" class to the "part" class.

3.

Type an association name, if needed.

An aggregation relationship is used to denote a whole/part relationship between classes. In this situation, one class logically contains another. Association and aggregation relationships are created identically during code generation.

To add generalization relationships:

1.

Select the Generalization toolbar button.

2.

Drag an arrow from the child class to the parent class.

A generalization relationship is used to show an inheritance relationship between two classes. The child class inherits all attributes, operations, and relationships of the parent.

To add dependency relationships:

1.

Select the Dependency toolbar button.

2.

Drag an arrow from one class to the other.

A dependency relationship is a weaker form of an association relationship. While one class still needs to communicate with the other, neither class is responsible for instantiating, destroying, or otherwise managing the other. When generating code for an association relationship, a reference to one class is created inside the other through a new attribute. With a dependency relationship, no attributes are created to support the relationship. Dependency relationships must be unidirectional.

695

Appendix: Getting Started with UML

Follow these steps to add multiplicity to the relationships:

1.

Right−click one end of the relationship.

2.

Select Multiplicity and then the appropriate multiplicity setting for that end of the relationship.

3.

Right−click the other end of the relationship and set its multiplicity.

Multiplicity shows how many instances of one class are related to a single instance of another class. Multiplicity indicators are placed at both ends of a relationship to show the number of instances in both directions. Multiplicity is not included on a generalization relationship.

To add role names to the relationships:

1.

Right−click one end of the relationship.

2.

Select Role Name.

3.

Type the role name on the diagram.

4.

Select the other end of the relationship and set its role name.

Role names indicate what role a class plays in a relationship. For example, in the relationship between Person and Company, a Person could play the role of Employee. Role names are used in the code−generation process; when an attribute is created to support a relationship, the attribute is named with the role name.

Building a Statechart Diagram

A Statechart diagram is used to show the dynamic behavior of an object. It shows the various states in which an object can exist, what state an object is in when it is created, what state an object is in when it is destroyed,

696

Appendix: Getting Started with UML

how an object moves from one state to another, and what an object does when it is in various states. All of this information helps a developer get a complete picture of how a particular object should behave.

Using Rose, you can create one or more Statechart diagrams for a class, and include all of the information listed above. Statechart diagrams do not need to be created for every class in a model. Classes with significant dynamic behavior, complex behavior, or behavior that is not well understood among the development team are good candidates for Statechart diagrams.

Follow these steps to create a Statechart diagram:

1.

Right−click a class in the browser.

2.

Select New → Statechart Diagram.

3.

Name the new diagram.

A Statechart diagram includes the various states, transitions, activities, and actions for an object in a particular class. Each class can have a single state/activity model, with one or more Statechart diagrams within it.

To add states to the diagram:

1.

Select the Client Page class button from the toolbar.

2.

Click in the diagram to add the class.

3.

Name the class.

697

Appendix: Getting Started with UML

A state is a condition in which an object can exist. For example, an invoice can be New, Paid, Delinquent, or Canceled. Each of these represents a different state.

To add start and end states:

1.

Select the Start State or End State button from the toolbar.

2.

Click in the diagram to place the start state or end state.

A start state shows the state an object is in when it is first instantiated. A Statechart diagram has one, and only one, start state. A start state is shown as a black dot on the diagram. An end state shows what state an object is in right before it is removed from memory. A Statechart diagram may have zero, one, or more end states. An end state is shown as a bull's−eye on the diagram.

To add activities to the states:

1.

Right−click the state and select Open Specification.

2.

Select the Actions tab.

3.

Right−click in the white space and select Insert.

4.

Double−click the new activity (the word "Entry/" in the list) to open the activity specification.

5.

Enter the activity details.

An activity is some bit of processing that occurs while the object is in a particular state. Activities can occur upon entry into the state, while exiting the state, while in the state, or upon a particular event.

To add transitions between the states:

1.

698