面向?qū)ο缶幊?- UML類圖

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容