30.1. The include Relationship
This is the most common and important relationship.It is common to have some partial behavior that is common across several use cases. For example, the description of paying by credit occurs in several use cases, including Process Sale, Process Rental, Contribute to Lay-away Plan , and so forth. Rather than duplicate this text, it is desirable to separate it into its own subfunction use case, and indicate its inclusion. This is simply refactoring and linking text to avoid duplication.[1]
[1] It is helpful if the links are implemented with navigable hyperlinks as well.
For example:
…Main Success Scenario :1.Customer arrives at a POS checkout with goods and/or services to purchase. … 7.Customer pays and System handles payment. …Extensions: 7b. Paying by credit: Include Handle Credit Payment .7c. Paying by check: Include Handle Check Payment . … |
…Extensions: 6b. Paying by credit: Include Handle Credit Payment . … |
…Level: SubfunctionMain Success Scenario :
2a. System detects failure to collaborate with external system: … |
…Extensions: 7b. Paying by credit: Handle Credit Payment .7c. Paying by check: Handle Check Payment . … |
Use include when you are repeating yourself in two or more separate use cases and you want to avoid repetition.
Another motivation is simply to decompose an overwhelmingly long use case into subunits to improve comprehension.
Using include with Asynchronous Event Handling
Yet another use of the include relationship is to describe the handling of an asynchronous event, such as when a user is able to, at any time, select or branch to a particular window, function, or Web page, or within a range of steps.In fact, the use case notation to support this asynchronous branching was already explored in the introduction to use cases in Chapter 6, but at that time the addition of calling out to an included sub-use case was not discussed.The basic notation is to use the a*, b*, ... style labels in the Extensions section. Recall that these imply an extension or event that can happen at any time. A minor variation is a range label, such as 3-9 , to be used when the asynchronous event can occur within a relatively large range of the use case steps, but not all.
…Main Success Scenario :
|
Summary
The include relationship can be used for most use case relationship problems. To summarize:
Factor out subfunction use cases and use the include relationship when:
|
As a first rule of thumb, always use the include relationship between use cases. People who follow this rule report they and their readers have less confusion with their writing than people who mix include with extend and generalizes [Cockburn01].