Activity: Capsule Design
Capsules are used to define concurrent threads of execution in the system. Capsules may be nested to an arbitrary depth, as well as having associations to design (passive) classes. This activity is performed once for each capsule, including new capsules identified within the scope of this activity. Create
Ports and Bind to Protocols
Consider the responsibilities of the capsule, creating an initial set of port classes. These port classes represent the 'interfaces' to the capsule. Port classes represent the realization of an Artifact: Protocol, which in turn represents a set of in and out signals used to communicate with capsules. In creating ports, consider the Checkpoints: Protocols to determine whether the Protocol is appropriate. The port should reflect a singular set of related responsibilities; having a similarly scoped protocol enables its re-use across a number of capsules. Once the appropriate protocol is selected, bind the port to the appropriate protocol. Validate Capsule Interactions
Once the ports are bound to protocols, the external behavior of the capsule must be evaluated and validated. Using either manual walk-through techniques or automated simulation tools, the behavior of the capsule should be tested by simulating the events that will exercise the capsule behavior. Validation will also consider the capsules which interact with the capsule under design. Using automated tools, stub code will need to be written within the capsule to allow the ports to be tested. Errors in protocol or port definition, or in capsule responsibilities, should be detected and appropriate changes to capsule, port and protocol definitions should be made. Define Capsule State Machines
Once the capsule ports and protocols have been validated, the internal behavior of the capsule must be defined. The behavior of the capsule is defined using a statechart diagram, refer to the Guidelines: Statechart Diagram. Other general capsule information can be obtained from Guidelines: Capsule and Checkpoints: Capsules. Define States
First, identify the states in which the capsule can exist. The states must be unique (a capsule cannot be in two states simultaneously) and descriptive. See the appropriate guidelines and checkpoints for more information. Define State Transitions
Once states are defined, consider the transitions between states. Transition code should read like high level application pseudo-code, it should consist primarily of real-time operating system service calls e.g., frame services, time services, port operations, capsule operations and passive class operations. When adding detail code to an Capsule transition:
When defining an Capsule operation:
Define
Requirements on Passive Classes
Based on the capsule state machines, examine the passive classes referenced by the capsule. If there are new requirements on these classes, change requests need to be generated to effect the required changes. If new classes have been identified, the requirements on these classes (most specifically the required operations on them) should be gathered together and the classes should be created. These classes will be further described in the Activity: Class Design. Introduce
Capsule Inheritance
Capsule inheritance is used to implement generalization-specialization, to make use of polymorphism, to reuse implementation. The key word here is 'implementation' - it is a technique that is used primarily to re-use the internal structure of capsules, not the external behavior of capsules. The primary purpose of Artifact: Protocols is to re-use behavioral definitions, so capsule inheritance should not be used for this purpose. Inheritance is often misapplied to achieve something that could more easily have been achieved using simpler design techniques. Using inheritance for generalization-specialization There are three kinds of inheritance. Listed from lowest complexity (most desirable) to most complex (least desirable), they are:
Problems with structural and behavioral inheritance
All designs containing structure/behavior have decisions and assumptions built in (either explicit or implicit). The critical question to ask is: are you absolutely sure that decision/assumption will always be valid? If not, what can you do to remove it or make it possible to change? Validate Capsule Behavior
As a final step, the behavior of the capsule must be evaluated and validated.
Using either manual walk-through techniques or automated simulation tools, the
behavior of the capsule should be tested by simulating the events that will
exercise the capsule behavior. In addition, the internal structure of the
capsule should be validated, ensuring that not only the external behavior but
also the internal implementation of that behavior is validated. Using automated
tools, stub code may need to be written to simulate the implementation of
passive data classes and external capsules with which the capsule interacts.
Defects detected should be documented and appropriate changes to capsule
definitions should be made. |
Rational Unified
Process |