UML类图
- Unified Modeling Language统一建模语言
- 关系,有泛化(Generalization), 实现(Realization),关联(Association),聚合(Aggregation),组合(Composition),依赖(Dependency)等
UML类图画图工具
- MS Office visio
- www.processon.com
- 类图结构
- 类名
- 属性名
(+) public属性名A:类型
(#) protected属性名B:类型
(-) private属性名C:类型- 方法名
(+) public方法名A(参数1,参数2):返回值类型
(#) protected方法名B(参数1,参数2):返回值类型
(-) private方法名C(参数1):返回值类型
关系(主要的两个)
- 泛化,表示继承
- 关联,表示引用
样例1
class Person{
constructor(name, age){
this.name = name
this.age = age
}
eat(){
}
drink(){
}
}
-
UML类图
样例2
class Person{
constructor(name, age, house){
this.name = name
this.age = age
this.house = house
}
eat() {
alert(`${this.name} eat something`)
}
}
class stu extends Person {
constructor(name, age, house, number){
super(name, age, house)
this.number = number
}
study() {
alert(this.number, this.name)
}
}
class stu1 extends Person {
constructor(name, age, house, number){
super(name, age, house)
this.number = number
}
study() {
alert(this.number, this.name)
}
}
class House {
constructor(city){
this.city = city
}
showCity() {
alert(this.city)
}
}