You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在UML类的文本规范中表示继承关系?

在指定UML类文本规范中表示继承关系的方法
  • 要表示继承(泛化)关系,只需在子类的类定义头部添加extends关键字,后跟父类的名称即可。
  • 子类会自动继承父类的所有features和operations,无需重复声明;若需重写父类方法,直接在子类中重新定义同名方法即可。

完整示例

**class** Vehicle
    **inv**: weight > 0;
    **features**:
        public brand: String;
        public maxSpeed: Integer;

**operations**:
    **public** startEngine(): Boolean {...}
    **comment**: "启动引擎,返回是否启动成功"
    **pre**: maxSpeed > 0;
    **post**: engineStatus == running;

**end** Vehicle

// 子类Car继承父类Vehicle
**class** Car **extends** Vehicle
    **inv**: seatCount >= 2;
    **features**:
        public seatCount: Integer;

**operations**:
    **public** openDoor(): Void {...}
    **comment**: "打开车门"
    **pre**: engineStatus == stopped;
    **post**: doorStatus == open;
    // 重写父类的startEngine方法
    **public** startEngine(): Boolean {...}

**end** Car

不忍2 loc中�其实教堂Optional不用那边Merge加厚查 Worker

注意:继承关系在UML图形中是从子类指向父类的空心箭头,而在这个文本规范里通过extends关键字直接关联子类与父类,语义上完全对应泛化关系。

内容的提问来源于stack exchange,提问作者Erik Radisch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 09:48:25