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

相关推荐
seconp13 小时前
AI 时代怎么做计算机毕业设计?
人工智能·毕业设计·软件工程·课程设计·毕设
郝学胜-神的一滴17 小时前
C++ Templates 07:编译报错和调试手段与实战技巧
开发语言·c++·后端·软件工程·visual studio
小南知更鸟18 小时前
飞利浦KeyLink软件分享下载
软件工程
RockHopper20252 天前
AI时代模型生命周期与软件资产重构:概要版
人工智能·系统架构·软件工程·ai编程·世界模型
記億揺晃着的那天3 天前
【Agent 架构实战】大模型长期项目开发:决策文档生命周期管理与 CI 门禁治理
软件工程·devops·架构设计·ai agent·文档管理
rolt3 天前
智能机床-06 机械 ISO 23704-4-2026-用UML表示的行业标准
软件工程·产品经理·架构师·uml
️公子3 天前
Claude Code 2.1.289 补上四个 deny 缺口:Agent 权限匹配器的规范化、分层裁决与回归语料
软件工程·ai agent·权限控制·claude code·安全工程
对讲机数码科普5 天前
数字集群对讲工程全流程拆解:DMR/ePDT 制式选型、组网落地与运维实战
运维·软件工程
硅谷秋水5 天前
EmbodiedSWE:面向长时程灵巧机器人的编程智能体
人工智能·机器学习·语言模型·机器人·软件工程
郝学胜-神的一滴5 天前
C++ Templates 03:手写一个Stack看透模板核心机制
开发语言·c++·产品运营·软件工程·产品经理