面向对象编程 - UML类图

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类图


    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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容