UML類圖
- Unified Modeling Language統(tǒng)一建模語言
- 關(guān)系,有泛化(Generalization), 實現(xiàn)(Realization),關(guān)聯(lián)(Association),聚合(Aggregation),組合(Composition),依賴(Dependency)等
UML類圖畫圖工具
- MS Office visio
- www.processon.com
- 類圖結(jié)構(gòu)
- 類名
- 屬性名
(+) public屬性名A:類型
(#) protected屬性名B:類型
(-) private屬性名C:類型- 方法名
(+) public方法名A(參數(shù)1,參數(shù)2):返回值類型
(#) protected方法名B(參數(shù)1,參數(shù)2):返回值類型
(-) private方法名C(參數(shù)1):返回值類型
關(guān)系(主要的兩個)
- 泛化,表示繼承
- 關(guān)聯(lián),表示引用
樣例1
class Person{
constructor(name, age){
this.name = name
this.age = age
}
eat(){
}
drink(){
}
}
-
UML類圖
image.png
樣例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)
}
}

image.png
