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

相关推荐
老郑聊AI业财智造3 小时前
给大模型装上“金融之眼”:Kronos-Report的量化预测架构与技术全景剖析
人工智能·python·深度学习·语言模型·金融·架构·软件工程
梁辰兴1 天前
软件工程:UML 的表示法
软件工程·uml·梁辰兴·uml的表示法·类图表示法·对象图表示法·用例图表示法
电子科技圈1 天前
IAR与东软睿驰达成战略合作,强化软件开发效率与生态协作
设计模式·开源·软件工程·软件构建·代码规范·设计规范·代码复审
皮卡丘不断更1 天前
Vibe Coding 有了接口原型后:用智能体做一份联调差异单
软件工程·智能体·vibe coding·接口联调
Dola_Zou1 天前
深入拆解 CmActLicense: 工业级“软授权”的架构设计与安全实践
安全·软件工程·软件加密
帅次2 天前
Git 常用命令汇总
git·软件工程·开发工具·版本控制·git教程·代码管理·git命令
梁辰兴2 天前
软件工程:对象模型技术方法简介
软件工程·梁辰兴·方法比较·对象模型技术方法简介·omt方法定义·三个模型·omt过程
老郑聊AI业财智造2 天前
Spring AI 技术架构与源码分析
java·人工智能·后端·spring·架构·软件工程
xierui1231232 天前
AI创作工作流状态管理:为什么保存 Prompt仍然无法复现作品
人工智能·自动化·prompt·aigc·软件工程
皮卡丘不断更2 天前
Vibe Coding 做完原型后:给网页项目加上任务、验证和人工确认
人工智能·软件工程