Chapter 5 Design
Advanced class modeling
Stereotypes
Extends an existing UML modeling element
Stereotypes are the main extensibility technique of UML. In the extensibility task, they are assisted by constraints and tags
Comments and constraints
Advanced generalization and inheritance modeling
Generalization and substitutability
Generalization reduces the number of association and aggregation(聚合) relationships in the model
**Substitutability principle :**a subclass object can be used in place of a superclass object
Inheritance versus encapsulation(封装)
-
Encapsulation
- Encapsulation refers to the class , not the object
- Encapsulation demands that an object’s state be accessible only through the operations in the object’s interface.
-
Implementation Inheritance
- Generalization can be used to imply substitutability, and be realized by an interface inheritance
- Generalization can also be used to imply code reuse, and be realized by an implementation inheritance
-
The evils of implementation inheritance
- Fragile base class
- Overriding and callbacks
- multiple implementation inheritance
Advanced aggregation and delegation modeling
🍓 Aggregation
Aggregation is a containment relationship
More semantics(语义学) needed
- “ExclusiveOwns” aggregation
- “Owns” aggregation
- “Has” aggregation
- “Member” aggregation
Generalization vs aggregation
Advanced interaction modeling
Execution specification : The time when the flow of control is focused in an object
Reply message: The return result from a message
Found message: represents a message whose sender is not specified
Fragments
- A piece of interaction is called an interaction fragment
- Interactions can contain smaller interaction fragments called combined fragments
- The semantics of a combined fragment is determined by the interaction operator
A reference to an interaction from an enclosing interaction is called an interaction use.
Sequence diagrams are the preferred visual tool for interaction modeling. They can be enriched with combined fragments and interaction uses.