当前位置:网站首页>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
边栏推荐
- Android Development: the client obtains the latest value in the database in real time and displays it on the interface
- mysql_linux版本的下載及安裝詳解
- std::stoi stol stoul stoll stof stod
- Openlayers 5.0 reload the map when the map container size changes
- Using bafayun to control the computer
- The corresponding permissions required to automatically open the app in the setting interface through accessibility service
- Quick start to static class variables
- I just want to leave a note for myself
- Simple use of navigation in jetpack
- On the forced conversion of C language pointer
猜你喜欢
JVM的类加载过程
Some records used by VS2010
为何PostgreSQL即将超越SQL Server?
FTP, SSH Remote Access and control
从技术体系到商业洞察,中小研发团队架构实践之收尾篇
C: generic reflection
MySQL学习第五弹——事务及其操作特性详解
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Using Visual Studio code to develop Arduino
Wechat applet part of the mobile phone Preview PDF did not respond
随机推荐
SQL常用的命令
Introduction to ROS learning notes (I)
Redis optimization series (III) solve common problems after master-slave configuration
std::stoi stol stoul stoll stof stod
Switching power supply design sharing and power supply design skills diagram
Raspberry pie 18b20 temperature
The type initializer for ‘Gdip‘ threw an exception
FTP、ssh远程访问及控制
Using 8266 as serial port debugging tool
SSDB基础3
Simple use of navigation in jetpack
Recyclerview control list item layout match_ Fundamental principle of parent attribute invalidation
mysql_linux版本的下載及安裝詳解
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
Class loading process of JVM
12个例子夯实promise基础
WebView saves the last browsing location
Get a list of recent apps
高层次人才一站式服务平台开发 人才综合服务平台系统
C1000k TCP connection upper limit test 1