Common Modeling Techniques
Modeling Roles
Objects represent single individuals in a situation or execution. They are useful within concrete examples, but most of the time we want to show general parts within some context. A part within a context is called a role. Perhaps the most important thing for which you'll use roles is to model the dynamic interactions. When you model such interactions, you are generally not modeling concrete instances that exist in the real world. Instead, you are modeling roles within a reusable pattern, within which the roles are essentially proxies or stand-ins for objects that will appear within individual instances of the pattern. For example, if you want to model the ways objects in a windowing application react to a mouse event, you'd draw an interaction diagram containing roles whose types include windows, events, and handlers.
Interactions are discussed in Chapters 16 and 19; internal structure is discussed in Chapter 15 . |
- Identify a context within which several objects interact.
- Identify those roles necessary and sufficient to visualize, specify, construct, or document the context you are modeling.
- Render these roles in the UML as roles in a structured context. Where possible, give each role a name. If there is no meaningful name for the role, render it as an anonymous role.
- Expose the properties of each role necessary and sufficient to model your context.
- Render these roles and their relationships in an interaction diagram or a class diagram.
NoteThe semantic difference between concrete objects and roles is subtle but not difficult. To be precise, a UML role is a predefined part of a structured classifier, such as a structured class or a collaboration. A role is not an object, but a description; a role is bound to a value within each instance of a structured classifier. A role therefore corresponds to many possible values, just as an attribute does. Concrete objects appear in specific examples, such as object diagrams, component diagrams, and deployment diagrams. Roles appear in generic descriptions as interaction diagrams and activity diagrams.
Interaction diagrams are discussed in Chapter 19; activity diagrams are discussed in Chapter 20 . |
Figure 28-5. Modeling Roles

Modeling the Realization of a Use Case
One of the purposes for which you'll use collaborations is to model the realization of a use case. You'll typically drive the analysis of your system by identifying your system's use cases, but when you finally turn to implementation, you'll need to realize these use cases with concrete structures and behaviors. In general, every use case should be realized by one or more collaborations. For the system as a whole, the classifiers involved in a given collaboration that is linked to a use case will participate in other collaborations as well. In this way, the structural contents of collaborations tend to overlap one another.
Use cases are discussed in Chapter 17 . |
- Identify those structural elements necessary and sufficient to carry out the semantics of the use case.
- Capture the organization of these structural elements in class diagrams.
- Consider the individual scenarios that represent this use case. Each scenario represents a specific path through the use case.
- Capture the dynamics of these scenarios in interaction diagrams. Use sequence diagrams if you want to emphasize the time ordering of messages. Use communication diagrams if you want to emphasize the structural relationships among these objects as they collaborate.
- Organize these structural and behavioral elements as a collaboration that you can connect to the use case via realization.
For example, Figure 28-6 shows a set of use cases drawn from a credit card validation system, including the primary use cases Place order and Generate bill, together with two other subordinate use cases, Detect card fraud and Validate transaction. Although most of the time you won't need to model this relationship explicitly (but will leave it up to your tools), this figure explicitly models the realization of Place order by the collaboration Order management. In turn, this collaboration can be further expanded into its structural and behavioral aspects, leading you to class diagrams and interaction diagrams. It is through the realization relationship that you connect a use case to its scenarios.
Figure 28-6. Modeling the Realization of a Use Case

Modeling the Realization of an Operation
Another purpose for which you'll use collaborations is to model the realization of an operation. In many cases, you can specify the realization of an operation by going straight to code. However, for those operations that require the collaboration of a number of objects, it's better to model their implementation via collaborations before you dive into code.
Operations are discussed in Chapters 4 and 9 . |
Notes are discussed in Chapter 6 . |
- Identify the parameters, return value, and other objects visible to the operation. These become roles of the collaboration.
- If the operation is trivial, represent its implementation directly in code, which you can keep in the backplane of your model, or explicitly visualize it in a note.
- If the operation is algorithmically intensive, model its realization using an activity diagram.
- If the operation is complex or otherwise requires some detailed design work, represent its implementation as a collaboration. You can further expand the structural and behavioral parts of this collaboration using class and interaction diagrams, respectively.
For example, Figure 28-7 shows the active class RenderFrame with three of its operations exposed. The function progress is simple enough to be implemented directly in code, as specified in the attached note. However, the operation render is much more complicated, so its implementation is realized by the collaboration Ray trace. Although not shown here, you could zoom inside the collaboration to see its structural and behavioral aspects.
Figure 28-7. Modeling the Realization of an Operation

Active classes are discussed in Chapter 23 . |
Activity diagrams are discussed in Chapter 20 . |
Modeling a Mechanism
In all well-structured object-oriented systems, you'll find a spectrum of patterns. At one end, you'll find idioms that represent patterns of use of the implementation language. At the other end, you'll find architectural patterns and frameworks that shape the system as a whole and impose a particular style. In the middle, you'll find mechanisms that represent common design patterns by which the things in the system interact with one another in common ways. You can represent a mechanism in the UML as a collaboration.
Patterns and frameworks are discussed in Chapter 29; an example of modeling a mechanism is discussed in the same chapter. |
- Identify the major mechanisms that shape your system's architecture. These mechanisms are driven by the overall architectural style you choose to impose on your implementation, along with the style appropriate to your problem domain.
- Represent each of these mechanisms as a collaboration.
- Expand on the structural and behavioral part of each collaboration. Look for sharing, where possible.
- Validate these mechanisms early in the development lifecycle (they are of strategic importance), but evolve them with each new release, as you learn more about the details of your implementation.