设计模式(一):面向对象 / UML 类图

1,概念:类、对象(实例)

2,描述:js是弱面向对象语言。

3,三要素:继承(extends) 封装(public,protected,private)多态

4,意义:数据结构化

框架设计:简单- 抽象。

 

UML(统一建模语言)类图

面向对象中类图格式 : 类 属性(public,类型) 方法 (private,返回值)

关系:泛化(继承-空心箭头),关联(引用-实心箭头)

示例(代码对应类图):

 

 

// 面向对象
// 继承  封装   多态
class Person {
  constructor(name,house) {
    this.name = name
    this.house = house
  }
  speak() {
    console.log('this',this)
  }
}

class House {
  constructor(city) {
    this.city = city
  }
  showCity() {
    console.log('_: ', this.city)
  }
}
class A extends Person {
  constructor(name,house) {
    super(name,house)
  }
}
let aHouse = new House('shenzhen')
let a = new A('name',aHouse)
a.house.showCity()

 

posted @ 2020-09-10 17:20  毛栗的demo  阅读(455)  评论(0)    收藏  举报