当前位置:网站首页>【UML】UML类图
【UML】UML类图
2022-06-30 18:01:00 【weixin_43224306】
安装步骤为:File -> Settings -> Plugins 搜索 PlantUML ,找到 PlantUML integration 并安装。
1.UML 基本介绍
1) UML——Unified modeling language UML (统一建模语言),是一种用于软件系统分析和设计的语言工具,它用于帮助软件开发人员进行思考和记录思路的结果
2) UML 本身是一套符号的规定,就像数学符号和化学符号一样,这些符号用于描述软件模型中的各个元素和他们之间的关系,比如类、接口、实现、泛化、依赖、组合、聚合等,如右图:

2.UML 图
画 UML 图与写文章差不多,都是把自己的思想描述给别人看,关键在于思路和条理,UML 图分类:
1) 用例图(use case)
2) 静态结构图:类图、对象图、包图、组件图、部署图
3) 动态行为图:交互图(时序图与协作图)、状态图、活动图
3.UML 类图
1) 用于描述系统中的类(对象)本身的组成和类(对象)之间的各种静态关系。
2) 类之间的关系:依赖、泛化(继承)、实现、关联、聚合与组合。
3) 属性/方法名称前加的加号和减号表示了这个属性/方法的可见性,UML类图中表示可见性的符号有三种:
+:表示public
-:表示private
#:表示protected
属性的完整表示方式是: 可见性 名称 :类型 [ = 缺省值]
方法的完整表示方式是: 可见性 名称(参数列表) [ : 返回类型]
4 .类图—依赖关(Dependence)
只要是在类中用到了对方,那么他们之间就存在依赖关系。如果没有对方,连编绎都通过不了。
public class PersonServiceBean {
private PersonDao personDao;//类
public void save(Person person){}
public IDCard getIDCard(Integer personid){}
public void modify(){
Department department = new Department();
}
}
public class PersonDao{}
public class IDCard{}
public class Person{}
public class Department{}类图:依赖

小结:
1) 类中用到了对方
2) 如果是类的成员属性
3) 如果是方法的返回类型
4) 是方法接收的参数类型
5) 方法中使用到
5.类图—泛化关(generalization)
泛化关系实际上就是继承关系,他是依赖关系的特例
public abstract class DaoSupport{
public void save(Object entity){
}
public void delete(Object id){
}
}
public class PersonServiceBean extends Daosupport{
}类图:继承

小结:
1) 泛化关系实际上就是继承关系
2) 如果 A 类继承了 B 类,我们就说 A 和 B 存在泛化关系
6.类图—实现关系(Implementation)
实现关系实际上就是 A 类实现 B 接口,他是依赖关系的特例
public interface PersonService {
public void delete(Interger id);
}
public class PersonServiceBean implements PersonService {
public void delete(Interger id){}
}类图:实现

小结:
7.类图--关联关系(Association)
关联关系实际上就是类与类之间的联系,它是依赖的特例
关联具有导航性:即双向关联或单项关联。
关系具有多重性:如"1"(表示有且仅有一个),"0..."(表示0个或多个),"0,1"(表示0个或者一个),“n,m”(表示n到m个都可以),“m...*”(表示至少m个)。
//单项一对一关系
public class Person{
private IDCard card;
}
public class IDCard{}
//双向一对一关系
public class Person{
private IDCard card;
}
public class IDCard{
private Person person;
}
//多对多关系类图:关联

小结:
关联类的属性的类型
8.类图—聚合关系(Aggregation)
聚合关系(Aggregation)表示的是整体和部分的关系,整体与部分可以分开。聚合关系是关联关系的特例,所以他具有关联的导航性与多重性。
如:一台电脑由键盘(keyboard)、显示器(monitor),鼠标等组成;组成电脑的各个配件是可以从电脑上分离出来的,使用带空心菱形的实线来表示。
public class Computer{
private Mouse mouse;
private Monitor monitor;
public void setMouse(Mouse mouse){
this.mouse = mouse;
}
public void setMonitor(Monitor monitor){
this.monitor = monitor;
}
}类图:聚合

小结:
聚合关系(Aggregation)表示的是整体和部分的关系,整体与部分可以分开。
9.类图—组合关系(Composition)
组合关系:也是整体与部分的关系,但是整体与部分不可以分开。
再看一个案例:在程序中我们定义实体:Person 与 IDCard、Head, 那么 Head 和 Person 就是 组合,IDCard 和Person 就是聚合。
但是如果在程序中 Person 实体中定义了对 IDCard 进行级联删除,即删除 Person 时连同 IDCard 一起删除,那 么 IDCard 和 Person 就是组合了.
public class Person{
private IDCard card;
private Head head = new Head();
}
public class IDCard{}
public class Head{}类图:组合聚合

public class Computer {
private Mouse mouse = new Mouse(); //鼠标可以和 computer 不能分离
private Moniter moniter = new Moniter();//显示器可以和 Computer 不能分离
public void setMouse(Mouse mouse) {
this.mouse = mouse;
}
public void setMoniter(Moniter moniter) {
this.moniter = moniter;
}
}
public class Mouse {
}
public class Moniter {
}类图:组合

小结:
组合引用类实例化时,被引用类也同时实例化
边栏推荐
- The folder is transferred between servers. The folder content is empty
- Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]
- Lenovo Yoga 27 2022, full upgrade of super configuration
- Small program container technology to promote the operation efficiency of the park
- 简述机器学习中的特征工程
- Can go struct in go question bank · 15 be compared?
- Swin-Transformer(2021-08)
- NFT technology for gamefi chain game system development
- 开发那些事儿:如何在视频中添加文字水印?
- 20220528 [talk about fake chips] those who are greedy for cheap often suffer heavy losses. Take stock of those fake memory cards and solid state drives
猜你喜欢

Opencv data type code table dtype

不同制造工艺对PCB上的焊盘的影响和要求

一点比较有意思的模块

Construction and practice of full stack code test coverage and use case discovery system

Video content production and consumption innovation

DTD modeling

年复一年,为什么打破数据孤岛还是企业发展的首要任务

Electron 入门

一套十万级TPS的IM综合消息系统的架构实践与思考

Browser window switch activation event visibilitychange
随机推荐
德国AgBB VoC有害物质测试
PC wechat multi open
NEON优化2:ARM优化高频指令总结
Practical application of "experience" crawler in work
opencv数据类型代码表 dtype
MySQL recursion
Adhering to the concept of 'home in China', 2022 BMW children's traffic safety training camp was launched
Kubernetes----Pod配置容器启动命令
Detailed single case mode
联想YOGA 27 2022,超强配置全面升级
20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘
不同制造工艺对PCB上的焊盘的影响和要求
Cloud Native Landing Practice Using rainbond for extension dimension information
一文详解|Go 分布式链路追踪实现原理
How to seamlessly transition from traditional microservice framework to service grid ASM
20200525 Biotechnology - Sichuan Normal University self taught Biotechnology (undergraduate) examination plan txt
传统微服务框架如何无缝过渡到服务网格 ASM
Kalman filter -- Derivation from Gaussian fusion
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(上)
Evolution of screen display technology