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

相关推荐
holeer11 天前
【V3.0】「酒店 × 视觉AI」项目 | 需求分析说明书(软件工程概论 - 课程作业三)
人工智能·软件工程·需求分析·原型设计·总体设计·结构化设计
雾江流11 天前
Xtra 2.54.1 | Twitch直播第三方客户端,开源纯净无广
软件工程
张较瘦_12 天前
[论文阅读] AI + 教育 | 不是单纯看视频!软件工程培训的游戏化融合之道
论文阅读·人工智能·软件工程
张较瘦_12 天前
[论文阅读] AI + 软件工程 | 用统计置信度破解AI功能正确性评估难题——SCFC方法详解
论文阅读·人工智能·软件工程
@insist12312 天前
软考-软件设计师-计算机体系结构核心考点与应用
软件工程·软考·软件设计师
零一iTEM13 天前
Bambu Studio 在Windows上无法启动
笔记·软件工程·学习方法
yzx99101313 天前
重构边界:软件工程与计算机科学的未来就业方向深度观
重构·软件工程
木枷14 天前
KIMI-DEV: AGENTLESS TRAINING AS SKILL PRIORFOR SWE-AGENTS
人工智能·软件工程
木枷16 天前
SWE-smith: Scaling Data for Software Engineering Agents
人工智能·软件工程
郝学胜-神的一滴16 天前
在Vibe Coding时代,学习设计模式与软件架构
人工智能·学习·设计模式·架构·软件工程