We know that object-oriented features are encapsulation, inheritance, and polymorphism. To make these relationships clearer, we often use UML class diagrams to represent them. Common relationships are as follows:
1. Class: indicates the encapsulation of an object. For example,
The top grid represents the class name, and italic indicates that the class is an abstract class. The second grid indicates the characteristics of the class, which is commonly referred to as fields and attributes. The third grid indicates the class operation,
That is, methods and actions. The preceding "+" indicates public, "-" indicates private, and "#" indicates protected.
2. Interface: refers to a series of method declarations that are not implemented. The class implementing this interface is responsible for implementing this interface.
The top one represents the interface name, and the second represents some methods defined by the interface.
3. inheritance: uses the existing class definition as the base class, which can add new data or functions, or use the features of the parent class, however, the parent class cannot be inherited selectively. The specific expression method is hollow triangle + solid line.
Of course, in Java, to implement a multi-Inheritance mechanism similar to C ++, there is also an implementation (implements) interface class diagram. The specific representation method is hollow triangle + dotted line or lollipop notation.
4. Association: When a class needs to "know" the other class, it can be expressed by association and expressed by the real-line arrow.
5. aggregation: a weak "ownership" relationship, which is equivalent to inclusion, but not a part of it, so that it can be distinguished from synthesis and expressed using hollow diamond + solid arrow.
6. composition: it is also called a combination. It is a kind of strong "ownership relationship". It reflects a local and overall relationship, and its lifecycle is the same as that of the whole, use solid diamond + solid arrow. The numbers in the two segments of the link represent the base number, indicating that a class can have several instances and a person has a head. Therefore, they are represented.
7. Dependency: for example, if a human wants to drink water or eat, the dependency is represented by a dotted arrow.
Note: Because my Visio functions are limited, no images in sections 4 and 5 can be drawn, and all of them are from the Internet. In case of any problems, no legal liability shall be incurred.