当前位置:网站首页>【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 {
}类图:组合

小结:
组合引用类实例化时,被引用类也同时实例化
边栏推荐
- Can go struct in go question bank · 15 be compared?
- MySQL transaction concurrency and mvcc mechanism
- Leader: who can use redis expired monitoring to close orders and get out of here!
- 基于 actix、async-graphql、rbatis、pgsql/mysql 构建 GraphQL 服务(4)-变更服务
- slice
- Word——Word在试图打开文件时遇到错误的一种解决办法
- BeanUtils.copyProperties() 对比 mapstruct
- VS 常用的快捷键指令
- Redis入门到精通01
- Where do the guests come from
猜你喜欢

Huaxing Securities: kitex practice under the original hybrid Cloud Architecture

Video content production and consumption innovation

20220607 fell below the recommended retail price, and the GPU market is moving towards oversupply

VMware16安装Win11虚拟机(最全步骤+踩坑)

Nodejs 安装与介绍

Some interesting modules

France a+ France VOC label highest environmental protection level

Kalman滤波器--从高斯融合推导

Brief introduction of Feature Engineering in machine learning
![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](/img/96/8e195536127b90d4eec54294371cad.png)
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
随机推荐
「经验」爬虫在工作中的实战应用『理论篇』
《所谓情商高,就是会说话》读书笔记
MySQL function to get the full path
4个技巧告诉你,如何使用SMS促进业务销售?
Brief introduction of Feature Engineering in machine learning
NBI visual platform quick start tutorial (V) introduction to editor functions and operations
Develop those things: how to add text watermarks to videos?
torch. roll
MySQL download and installation tutorial
Lenovo Yoga 27 2022, full upgrade of super configuration
torch stack() meshgrid()
Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched
【社区明星评选】第23期 7月更文计划 | 点滴创作,汇聚成塔!华为FreeBuds 4E等酷爽好礼送不停
How to improve the three passive situations in data analysis
The folder is transferred between servers. The folder content is empty
Memory Limit Exceeded
期货怎么开户安全些?现在哪些期货公司靠谱些?
France a+ France VOC label highest environmental protection level
Personally test the size of flutter after packaging APK, quite satisfied
20200525 Biotechnology - Sichuan Normal University self taught Biotechnology (undergraduate) examination plan txt