OMT画图的五种结构表达方式

  1. 实例化:A类依赖于B类。

    javascript 复制代码
    class B {
      doSth () {
    
      }
    }
    
    class A {
      constructor () {}
    
      run () {
        const b = new B()
        b.doSth()
      }
    }
    
    new A().run()
  2. 委托:A对象依赖于B对象。

    javascript 复制代码
    class B {
      doSth () {
    
      }
    }
    const b = new B()
    
    class A {
      constructor () {}
    
      run () {
        b.doSth()
      }
    }
    new A().run()
  3. 聚合:A对象和B对象是"has-a"关系。

    javascript 复制代码
    class Student {  
      constructor(name) {  
        this.name = name  
      }
    }
    
    class Classroom {  
      constructor() {  
        this.students = []  
      }
    
      addStudent(student) {  
        this.students.push(student)  
      }  
    }
    
    let student1 = new Student('Alice')  
    let student2 = new Student('Bob')  
    let classroom = new Classroom()  
    classroom.addStudent(student1)  
    classroom.addStudent(student2)
  4. 组合:A对象和B对象是"is-a"关系。

    javascript 复制代码
    class Creature {  
      constructor(name) {  
        this.name = name  
      }  
    }  
    
    class Eye {  
      constructor(color) {  
        this.color = color  
      }  
    }  
    
    class Human extends Creature {  
      constructor() {  
        super('Human')  
        this.leftEye = new Eye('blue')  
        this.rightEye = new Eye('brown')  
      }  
    }
  5. 继承:A类和B类是"is-a"关系。

相关推荐
小草cys2 天前
先理解软件工程,再谈AI辅助研发
人工智能·软件工程
CSTechEi4 天前
【SPIE/EI/Scopus检索】2025 年第二届数据挖掘,计算与软件工程国际会议 (DMCSE 2025)
人工智能·数据挖掘·软件工程·信息与通信·ei学术会议
江梦寻5 天前
软件工程教学评价
开发语言·后端·macos·架构·github·软件工程
吕永强5 天前
大话软工笔记—需求分析概述
项目管理·软件工程
张较瘦_5 天前
[论文阅读] 人工智能+软件工程(软件测试) | 当大语言模型遇上APP测试:SCENGEN如何让手机应用更靠谱
论文阅读·人工智能·软件工程
二倍本贝5 天前
【慧游鲁博】【12】小程序端 · 智能导览对接后端文物图片识别功能
小程序·uni-app·vue·软件工程
电子科技圈6 天前
IAR开发平台升级Arm和RISC-V开发工具链,加速现代嵌入式系统开发
arm开发·嵌入式硬件·设计模式·性能优化·软件工程·代码规范·risc-v
哆啦A梦的口袋呀6 天前
理解系统交互:UML时序图
软件工程·交互·uml
张较瘦_7 天前
[论文阅读] 人工智能+软件工程 | 理解GitGoodBench:评估AI代理在Git中表现的新基准
论文阅读·人工智能·软件工程
吕永强7 天前
大话软工笔记—需求分析详解
项目管理·软件工程·需求分析