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

相关推荐
workflower7 小时前
如何对比软件需求做的是否合格?
设计模式·软件工程·需求分析
hope_wisdom1 天前
实战设计模式之外观模式
设计模式·架构·软件工程·软件构建·外观模式·架构设计
云纳星辰怀自在2 天前
软件工程之软件需求SWE.1
软件工程·需求分析
xiaohiiii2 天前
2012年下半年软件设计师上午题知识点及其详细解释(附真题及答案解析)
运维·服务器·数据库·计算机网络·职场和发展·软件工程
workflower3 天前
实例研究:设计一个文档编辑器(24)- 完
java·开发语言·设计模式·编辑器·软件工程·需求分析·软件需求
IDRSolutions_CN3 天前
Java 开发者需要了解的 PDF 基础知识
java·经验分享·pdf·软件工程·团队开发
odoo中国6 天前
2.Part1 第一章 软件工程的定义与实践
软件工程
風落7 天前
称呼计算器:智能科技,简化您的计算生活
windows·科技·电脑·生活·软件工程·软件需求
風落7 天前
PDF Shaper:免费多功能 PDF 工具箱,一站式满足您的 PDF 需求!
windows·pdf·电脑·软件工程·软件需求
思茂信息9 天前
CST的TLM算法仿真5G毫米波阵列天线及手机
网络·人工智能·5g·智能手机·软件工程·软件构建