Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to master UML class diagram

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to master UML class diagrams". In daily operation, I believe many people have doubts about how to master UML class diagrams. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to master UML class diagrams"! Next, please follow the editor to study!

Rural love class map learning

UML (Unified Modeling Language) is a modeling tool for object-oriented design. The core of modeling is the model, which is the simplification and abstraction of reality.

In UML, all the descriptions include: transaction, relationship and diagram. The following figure shows the relationship of all components.

UML component diagram, from design pattern

Next, we will focus on the class diagram relationship in UML, which is reflected in rural love characters.

1. Class diagram model

UML class diagram (Class Diagrams) is one of the most frequently used UML diagrams, which can show classes, interfaces, and the collaborative relationships between them. Each interface, class, property, and method can be expressed in the following way.

In the UML class diagram, interfaces, classes, properties, methods, expressions

two。 Inheritance relationship code

Public class Xie Guangkun {private String generation; public void as a demon () {} public class Xie Yongqiang extends Xie Guangkun {} public class Xie Jian extends Xie Guangkun {}

Class diagram

UML class diagram, inheritance relationship

Function: inheritance relationship

Concept: Generaliztion, also known as generalization, is used to indicate that a subclass inherits all the functions of the parent class.

Scene: Xie Guangkun's demon skills, inherited by Xie Yongqiang and Xie Ji. Xie Ji inherits better and is more capable of doing.

3. Realization relationship

Code

Public interface dance {void moves ();} public class Liu Neng implements dance {private String to name; public void moves () {}} public class Zhao Si implements dance {private String to name; public void moves () {}}

Class diagram

UML class diagram, implementation relationship

Function: implementing relationships

Concept: interfaces, methods declared by abstract classes, which Realiztion their functions.

Scene: in a dance match between Zhao Sihua and Liu Neng, Zhao Sihua walked and was kicked and knocked down by Liu Neng.

4. Combinatorial relationship

Code

Public class marriage certificate {private Zhao Yutian husband, private Liu Ying woman, public void set husband (Zhao Yutian husband) {this. Public void set woman (Liu Ying woman) {this. Woman = woman;}} public class Zhao Yutian {private int age; private String gender;} public class Liu Ying {private int age; private int sex;}

Class diagram

UML class diagram, combinatorial relationship

Function: combinatorial relationship

Concept: the Combination relation represents the relationship between the whole and the part in the class, and the whole and the part depend on each other.

Scene: the marriage licenses of Zhao Yutian and Liu Ying are indispensable.

5. Aggregate relationship code

Public class Villa {private Song Xiaofeng Xiaofeng; private Li Baoku Treasure House; public void Medicine Catering Room (Li Baoku Treasure House) {this. Treasure house = treasure house;} public void Security (Song Xiaofeng Xiaofeng) {this. Xiaofeng = Xiaofeng;}} public class Li Baoku {private String occupation;} public class Song Xiaofeng {private String career;}

Class diagram

UML class diagram, aggregation relationship

Function: aggregation relationship

Concept: Aggregate relationships are also used to represent the whole and part of an object, but member objects can exist independently of the overall object.

Scene: in ⛰Villa, there is Li Baoku in the traditional Chinese medicine diet and Song Xiaofeng in the Security Department. But Li Baoku and Song Xiaofeng are just one of them, and both can leave the villa.

6. Association relationship

Code

Public class tofu factory {private Wang Xiaomeng employee; public void added employee (Wang Xiaomeng) {this. Employee = Xiaomeng;}} public class Wang Xiaomeng {private tofu factory enterprise; public void addition enterprise (tofu factory tofu factory) {this. Enterprise = tofu factory;}}

Class diagram

UML class diagram, association relationship

Function: Association relationship

Concept: Association relationship is a common relationship between classes, which represents the relationship between one kind of object and another kind of object. Combination and aggregation also belong to this relationship, but the correlation is weaker.

Scene: there is Wang Xiaomeng in the tofu factory, but there is not only Wang Xiaomeng but also Wang Laoqi in the tofu factory. Even if Xiaomeng is away, the tofu factory can operate normally. And Wang Xiaomeng has his own other enterprises, so this belongs to a kind of related relationship.

7. Dependency relationship

Code

Public class investment {public void investment (Wang Dana big shot) {}} public class Wang Dana {private String resources;}

Class diagram

UML class diagrams, dependencies

Function: dependency

Concept: Dependency relationships you can use dependencies when representing a transaction that requires the use of another transaction.

Scene: Wang Dana is needed to attract investment, but it is not the only one. If Wang Dana can't bring it, there may be Li Dana and Zhang Dana.

Panoramic class diagram of Zhao Jiaban

To sum up, in these six relationships, the structure of composition, aggregation and association code is similar, which can be understood from the strength of dependency. The strength relationship is in the following order: inheritance > implementation > combination > aggregation > association > dependency.

To express the UML class relationship more clearly, we draw these into a whole diagram, as follows

UML class diagram, Zhao Jiaban panoramic class diagram

Summary

Some people say, what if we and aliens? A very friendly correspondence. So there will be some communication between the two planets, such as saying, "Hello, earthlings?" How tall are you? The earth says 1.75 meters. The alien is dizzy. What is the unit of rice? In this way, we can only choose the standard commonly used by the two planets to define, for example, 1 meter is the distance that light travels in a vacuum in 1max 299792458 seconds.

In fact, the same is true of program development. In order to reduce the communication cost of understanding the content of new knowledge, we need to define some communication standards, such as UML class diagram. So we need to learn these standard instrumental languages to reduce communication costs and improve work efficiency.

UML class diagrams are also the most commonly used artwork and are easy to master. In order to lay their own knowledge more perfect, the technology stack to master more solid, but also in order to break through the bottleneck of each stage. Then you need to keep learning, accumulate constantly, and find opportunities to break the situation.

At this point, the study of "how to master UML class diagram" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report