Common Modeling Techniques
Modeling the Semantics of a Class
The most common purpose for which you'll use classes is to model abstractions that are drawn from the problem you are trying to solve or from the technology you are using to implement a solution to that problem. Once you've identified those abstractions, the next thing you'll need to do is specify their semantics.
The common uses of classes are discussed in Chapter 4 . |
Modeling is discussed in Chapter 1; you can also model the semantics of an operation using an activity diagram, as discussed in Chapter 20 . |
- Specify the responsibilities of the class. A responsibility is a contract or obligation of a type or class and is rendered in a note attached to the class, or in an extra compartment in the class icon.
Responsibilities are discussed in Chapter 4 . - Specify the semantics of the class as a whole using structured text, rendered in a note (stereotyped as semantics) attached to the class.
Specifying the body of a method is discussed in Chapter 3 . - Specify the body of each method using structured text or a programming language, rendered in a note attached to the operation by a dependency relationship.
- Specify the pre- and postconditions of each operation, plus the invariants of the class as a whole, using structured text. These elements are rendered in notes (stereotyped as precondition, postcondition, and invariant) attached to the operation or class by a dependency relationship.
Specifying the semantics of an operation is discussed in Chapter 20. State machines are discussed in Chapter 22; collaborations are discussed in Chapter 28; internal structures are discussed in Chapter 15. OCL is discussed in The Unified Modeling Language Reference Manual. - Specify a state machine for the class. A state machine is a behavior that specifies the sequences of states an object goes through during its lifetime in response to events, together with its responses to those events.
- Specify internal structure of the class.
- Specify a collaboration that represents the class. A collaboration is a society of roles and other elements that work together to provide some cooperative behavior that's bigger than the sum of all the elements. A collaboration has a structural part as well as a dynamic part, so you can use collaborations to specify all dimensions of a class's semantics.
- Specify the pre- and postconditions of each operation, plus the invariants of the class as a whole, using a formal language such as OCL.
Pragmatically, you'll end up doing some combination of these approaches for the different abstractions in your system.