当前位置:网站首页>【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 {
}
类图:组合
小结:
组合引用类实例化时,被引用类也同时实例化
边栏推荐
- Huaxing Securities: kitex practice under the original hybrid Cloud Architecture
- Is it safe to open an account for goucai? Is it reliable?
- Electron 入门
- 全栈代码测试覆盖率及用例发现系统的建设和实践
- Four tips tell you how to use SMS to promote business sales?
- [community star selection] the 23rd issue of the July revision plan | bit by bit creation, converging into a tower! Huawei freebuses 4E and other cool gifts
- Neon optimization 2: arm optimization high frequency Instruction Summary
- 4个技巧告诉你,如何使用SMS促进业务销售?
- Mipi protocol in RFFE
- 不同制造工艺对PCB上的焊盘的影响和要求
猜你喜欢
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
Huaxing Securities: kitex practice under the original hybrid Cloud Architecture
Full recharge, im+rtc+x full communication service "feedback season" starts
正则表达式(正则匹配)
Dlib library for face key point detection (openCV Implementation)
MySQL transaction concurrency and mvcc mechanism
Construction and practice of full stack code test coverage and use case discovery system
Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]
全栈代码测试覆盖率及用例发现系统的建设和实践
VMware16安装Win11虚拟机(最全步骤+踩坑)
随机推荐
Redis入门到精通01
Development: how to install offline MySQL in Linux system?
20200525 Biotechnology - Sichuan Normal University self taught Biotechnology (undergraduate) examination plan txt
Detailed single case mode
一文详解|Go 分布式链路追踪实现原理
Regular expressions (regular matching)
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
华兴证券:混合云原生架构下的 Kitex 实践
Lenovo Yoga 27 2022, full upgrade of super configuration
[community star selection] the 23rd issue of the July revision plan | bit by bit creation, converging into a tower! Huawei freebuses 4E and other cool gifts
How to open a futures account safely? Which futures companies are more reliable now?
详解单例模式
Go redis connection pool
TCP packet sticking problem
开发那些事儿:如何在视频中添加文字水印?
Coding officially entered Tencent conference application market!
CODING 正式入驻腾讯会议应用市场!
Small program container technology to promote the operation efficiency of the park
mysql 递归
基于UDP协议设计的大文件传输软件