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"关系。

相关推荐
张较瘦_1 天前
[论文阅读] 人工智能 + 软件工程 | 技术债务管理新范式:五步法工作坊与行动研究实践
人工智能·软件工程
张较瘦_3 天前
[论文阅读] 人工智能 + 软件工程 | 当AI成为文学研究员:Agentic DraCor如何用MCP解锁戏剧数据分析
论文阅读·人工智能·软件工程
广州智造4 天前
EPLAN教程:流体工程
开发语言·人工智能·python·算法·软件工程·软件构建
张较瘦_5 天前
[论文阅读] 软件工程工具 | EVOSCAT可视化工具如何重塑软件演化研究
论文阅读·软件工程
大千AI助手7 天前
SWE-bench:真实世界软件工程任务的“试金石”
人工智能·深度学习·大模型·llm·软件工程·代码生成·swe-bench
Q_Q5110082857 天前
python的软件工程与项目管理课程组学习系统
spring boot·python·django·flask·node.js·php·软件工程
万能小锦鲤7 天前
《软件工程导论》实验报告五 设计建模工具的使用(一)类图
软件工程·类图·实验报告·boardmix·文档资源
数据爬坡ing9 天前
过程设计工具深度解析-软件工程之详细设计(补充篇)
大数据·数据结构·算法·apache·软件工程·软件构建·设计语言
紫金桥软件9 天前
紫金桥RealSCADA:国产工业大脑,智造安全基石
安全·系统安全·软件工程
曼岛_10 天前
[系统架构设计师]软件工程基础知识(五)
系统架构·软件工程·系统架构设计师