当前位置:网站首页>UML类图几种关系的总结
UML类图几种关系的总结
2022-04-23 19:12:00 【如来神掌十八式】
在UML类图中,常见的有以下几种关系:泛化(Generalization), 实现(Realization),关联(Association),聚合(Aggregation),组合(Composition),依赖(Dependency)
1.泛化(Generalization)
【泛化关系】:是一种继承关系,它指定了子类如何特化父类的所有特征和行为例如:老虎是动物的一种.
【箭头指向】:带三角箭头的实线,箭头指向父类

2.实现(Realization)
【实现关系】:是一种类与接口的关系,表示类是接口所有特征和行为的实现
【箭头指向】:带三角箭头的虚线,箭头指向接口

3.关联(Association)
【关联关系】:是一种拥有的关系,它使一个类知道另一个类的属性和方法;如:老师与学生,丈夫与妻子
关联可以是双向的,也可以是单向的。双向的关联可以有两个箭头或者没有箭头,单向的关联有一个箭头。
【代码体现】:成员变量
【箭头及指向】:带普通箭头的实心线,指向被拥有者

上图中,老师与学生是双向关联,老师有多名学生,学生也可能有多名老师。但学生与某课程间的关系为单向关联,一名学生可能要上多门课程,课程是个抽象的东西他不拥有学生。

上图为自身关联:
4. 聚合(Aggregation)
【聚合关系】:是整体与部分的关系.如车和轮胎是整体和部分的关系.
聚合关系是关联关系的一种,是强的关联关系;关联和聚合在语法上无法区分,必须考察具体的逻辑关系。
【代码体现】:成员变量
【箭头及指向】:带空心菱形的实心线,菱形指向整体

5. 组合(Composition)
【组合关系】:是整体与部分的关系.,没有公司就不存在部门 组合关系是关联关系的一种,是比聚合关系还要强的关系,它要求普通的聚合关系中代表整体的对象负责代表部分的对象的生命周期
【代码体现】:成员变量
【箭头及指向】:带实心菱形的实线,菱形指向整体

6. 依赖(Dependency)
【依赖关系】:是一种使用的关系,所以要尽量不使用双向的互相依赖。
【代码表现】:局部变量、方法的参数或者对静态方法的调用
【箭头及指向】:带箭头的虚线,指向被使用者

各种关系的强弱顺序:
泛化= 实现> 组合> 聚合> 关联> 依赖
下面这张UML图,比较形象地展示了各种类图关系:

版权声明
本文为[如来神掌十八式]所创,转载请带上原文链接,感谢
https://blog.csdn.net/t194978/article/details/124362342
边栏推荐
- [record] typeerror: this getOptions is not a function
- Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
- Is it safe to open an account in Bohai futures.
- 剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
- [记录]TypeError: this.getOptions is not a function
- [报告] Microsoft :Application of deep learning methods in speech enhancement
- ArcGIS JS API dojoconfig configuration
- Android Development: the client obtains the latest value in the database in real time and displays it on the interface
- C: generic reflection
- WebView saves the last browsing location
猜你喜欢

JVM的类加载过程

Switching power supply design sharing and power supply design skills diagram

Redis optimization series (III) solve common problems after master-slave configuration

Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.

Simplified path (force buckle 71)
![[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born](/img/0a/ed4eab6589e1c072edc247463e889e.png)
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born

Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique

ESP32 LVGL8. 1 - msgbox message box (msgbox 28)

Raspberry pie uses root operation, and the graphical interface uses its own file manager

Client interns of a large factory share their experience face to face
随机推荐
MVVM model
openlayers draw矩形
After opening the original normal project, the dependency package displays red and does not exist.
7、 DOM (Part 2) - chapter after class exercises and answers
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
C: generic reflection
该买什么设备,Keysight 给你挑好了
Tencent cloud GPU best practices - remote development training using jupyter pycharm
Simplified path (force buckle 71)
Recyclerview control list item layout match_ Fundamental principle of parent attribute invalidation
Oracle配置st_geometry
Use of content provider
Tencent map and high logo removal method
JVM的类加载过程
Network protocol: SCTP flow control transmission protocol
mysql_linux版本的下載及安裝詳解
Using 8266 as serial port debugging tool
Convert string to JSON
Using Visual Studio code to develop Arduino
SSDB Foundation