1、UML 概述
- 是一种通用的可视化建模语言,通过一些标准的图形符号和文字来对系统进行建模,用于对软件进行描述、可视化处理、构造和建立软件系统制品的文档。
2、UML 种类
3、类图
-
概述:是业务结构建模的重要工具,可以表达类、接口以及类之间的静态结构和关系。
-
图示
-
代码
public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
4、类之间的关系
4.1 关联关系
-
概述
:用于表示一类对象与另一类对象之间有联系,通常将一个类的对象作为另一个类的成员变量。 -
单向关联
class Customer {
private Address address;
}
class Address {
}
双向关联
class Customer {
private Product[] products;
}
class Product {
private Customer customer;
}
聚合关系
class Car {
private Engine engine;
public Car(Engine engine) {
this.engine = engine;
}
public void setEngine(Engine engine) {
this.engine = engine;
}
}
class Engine {
}
组合关系
class Head {
private Mouth mouth;
public Head() {
this.mouth = new Mouth();
}
}
class Mouth {
}
4.2 依赖关系
public class Car {
public void move() {
}
}
public class Driver {
public void drive(Car car) {
car.move();
}
}
4.3 泛化关系
public class Person {
protected String name;
protected int age;
public void move() {
}
public void say() {
}
}
public class Student extends Person {
private String studentNo;
public void study() {
}
}
public class Teacher extends Person {
private String teacherNo;
public void teach() {
}
}
4.4 实现关系
public interface Vehicle {
void move();
}
public class Ship implements Vehicle {
@Override
public void move() {
}
}
public class Car implements Vehicle {
@Override
public void move() {
}
}