Class Diagram
1. Class Diagram Summary
★The main purpose of the class diagram is to reflect the structure of the class (attributes, operations) and the relationship between the classes. It describes the structure of the software system and is a static modeling method.
★The "class" in the class diagram corresponds to the concept of "class" in the object-oriented language, which is an abstraction of things in the real world
2. Things and explanations in the class diagram
(1) Category
1. It is divided into three parts from top to bottom, namely class name, attribute and operation. class name is required
2. If a class has attributes, each attribute must have a name, and can also have other descriptive information, such as visibility, data type, default value, etc.
3. If the class has operations, each operation also has a name, and other optional information includes visibility, parameter names, parameter types, parameter default values, and the type of return value of the operation, etc. (2
) interface
A set of operations, only the declaration of the operation but no implementation
(3) Abstract class
A class that cannot be instantiated, generally contains at least one abstract operation
(4) Template class
A parameterized class that binds template parameters to different data types at compile time, resulting in different classes
3. The relationship and explanation in the class diagram
(1) Association relationship - describes the relationship between the structure of the class. Has information such as direction, name, role, and multiplicity. General association semantics are weak.
There are also two strong semantics, namely aggregation and combination
1. Aggregation relationship - special association relationship, indicating the relationship between an aggregate (whole) and its components
2. Composition relationship - aggregation with stronger semantics, part and whole have the same life cycle
(2) Generalization relationship——※In object-oriented, it is generally called inheritance relationship, which exists between parent class and subclass, parent interface and subinterface. (3) Realization relationship
—corresponding to between classes and interfaces The relationship
(4) Dependency relationship - ※ describes the situation in which a change in a class affects the class that depends on it. There are many forms of expression, such as binding (bind), friend (friend), etc.
4. Mapping between class diagrams and codes
(1) Class mapping
(2) Mapping of association relationship
(3) Mapping of generalization relationship
(4) Mapping of realization relationship
(5) Mapping of dependency relationship
5. Example of class diagram
(1) Graphics editor
(1) Performance Ticketing System