My understanding of the relationship between uml class diagrams and my understanding of uml class diagrams
Relationship between uml class diagrams:
Generalization is inheritance. An Implementation relationship is a class that implements another interface. Dependency is a class that uses another class. It is a usage relationship. In a service of this class, another class is needed for assistance. An association is a type that has another class and a type of ownership. This class requires assistance from another class during creation, it can be bidirectional, but it is best to change from business focus to unidirectional. The aggregation relationship is the relationship between the whole and the part, but the part can leave the whole. The composite relationship is also the relationship between the whole and the part, but the lifecycle of the two is bound together, and the part cannot leave the whole.
We prefer the classification of our eldest brother:
Polymorphism: generalized relationship. Dependency: Association, aggregation, and combination
For more information, see blog
Graphical representation of graph-like relationships:
General relationship (inheritance)
(Solid line with a triangular arrow. the arrow points to the parent class)
Code-level representation:
General Relationship
Public Class Tigger extends Animal {
Implementation relationship
Public Class Course implements Goods {
Dependency
Local variables, method parameters, or calls to static methods
Association, aggregation, and combination are all member variables.
In actual application, you must determine the class relationship based on the actual requirement description.The relationship between the class and the class must be determined based on actual needs. In other words, the relationship between the two classes can be determined under a certain semantics to objectively and truthfully reflect the actual needs.
For example, the semantic environment is: "A car has four wheels, and a car with a wheel can drive. The wheel itself has its own characteristics (color, size )"
Then we can extract the cars and wheels. How can we determine their relationship ??
Based on the uml class relationship, we can exclude implementation and inheritance, so there will be associations and dependencies. dependencies emphasize usage relationships, while associations emphasize ownership relationships, if you have a wheel, you can drive.
We can infer that they do not use the relationship, but have the relationship. Cars must own the wheel. So it should be:
For example, the semantic environment "the wheel to be detached should be placed in the garage". Based on this sentence, we can extract two classes.
What is the relationship between wheel and garage?
It is certainly not implementation and inheritance, but whether it is dependency or association. According to the sentence "putting the wheel in the garage", it can be concluded that the garage should provide a service for storing the wheels,
The two are used instead of having a relationship. Therefore:
Another way to determine the relationship between classesSemantic Description "one learning video has multiple knowledge points, and one knowledge point can be owned by multiple videos"
There is also a way to determine the relationship between two classes and use the code of the class relationship to reflect and determine the class relationship:
The Code of dependency is reflected in method parameters, local variables, and static method calls.
The code of the association is a member variable.
According to the description of "One learning video has multiple knowledge points", the video class must have a member variable of list <knowledge point class>,
According to the description "One knowledge point can be owned by multiple videos", we can know that the knowledge point class also has a list <video class> member variable,
Therefore, we can conclude that the video class and knowledge point are associated.
How to determine the starting point of the relationship between many-to-many and many-to-many ??Or the above semantic description "one learning video has multiple knowledge points, and one knowledge point can be owned by multiple videos"
From the above analysis, we can determine that the video class is associated with the knowledge point. If we make a two-way arrow when pointing, it will be difficult to understand, for example:
Therefore, our team's approach is to focus on your business. For example, if you are engaged in Video-related services, you should point the arrows to knowledge points.
After determining that the class link is an association link, how do we embody the class link we created? For example, one-to-many or many-to-many association relationships?Some people may think that the code for associating a link is a member variable. Isn't it enough to directly use the member variable?
For example:
One to multiple:
1. Put a multi-type set member variable in it.
Many to many:
Both parties store member variables of each type set.
However, it is very troublesome for us to make data persistent.
So our practice is:
If it is a one-to-many operation, it will store one or more primary key IDs in it, for example:
A video must belong to a teacher, and the code
For many-to-many operations, we use Relational Tables,
For example, for the relationship between videos and knowledge points, we will create a relational table to carry this many-to-many relationship, which is not reflected in the Entity class.