当前位置:网站首页>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
边栏推荐
- 【C语言进阶11——字符和字符串函数及其模拟实现(2))】
- One stop service platform for high-level talents and development of comprehensive service platform system for talents
- Android Development: the client obtains the latest value in the database in real time and displays it on the interface
- SQL Server database in clause and exists clause conversion
- c1000k TCP 连接上限测试1
- Tencent cloud GPU best practices - remote development training using jupyter pycharm
- #yyds干货盘点#stringprep --- 因特网字符串预备
- 该买什么设备,Keysight 给你挑好了
- Esp32 (UART ecoh) - serial port echo worm learning (2)
- Minesweeping II of souI instance
猜你喜欢
MySQL restores or rolls back data through binlog
Redis optimization series (III) solve common problems after master-slave configuration
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
Class loading process of JVM
2022.04.23(LC_763_划分字母区间)
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
Practice of Druid SQL and security in meituan review
c#:泛型反射
[记录]TypeError: this.getOptions is not a function
随机推荐
Oracle配置st_geometry
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
I just want to leave a note for myself
2022.04.23 (lc_763_divided into letter interval)
Some records used by VS2010
Openlayers 5.0 two centering methods
SQL server requires to query the information of all employees with surname 'Wang'
Fundamentals of machine learning theory -- some terms about machine learning
Openlayers 5.0 thermal diagram
JS to get the local IP address
redis优化系列(三)解决主从配置后的常见问题
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
SSDB foundation 1
Redis common interview questions
MySQL restores or rolls back data through binlog
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
An 8266 crash
js获取本机ip地址
Transaction processing of SQL Server database
c#:泛型反射