知识卡片
集中管理多态变体
集合每项只引用 Pet,在 Pet 上集中声明各合法分支,可让使用方少了解具体变体。若各业务对象自行枚举分支,新增类型时必须逐处更新。集中后的嵌套组合要确认目标工具能读懂。
结构图:
classDiagram
class Job
class Pet {
string name
integer age
}
class Cat {
string breed
}
class Dog {
string breed
string size
}
Pet <|-- Cat
Pet <|-- Dog
Job --> "1..*" Pet : pets
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Designing schemas with composition in OpenAPI 16.4 Polymorphism and inheritance in OpenAPI · 查看原书依据
Both options that we discussed in this chapter would work for PetSitter. The second option is closer to the domain model, since no changes are required within Job when we add new pets, and we have all the complex composition logic in
参考来源
- 位置:《Designing APIs with Swagger and OpenAPI》第16章《Designing schemas with composition in OpenAPI》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch16.htm,阅读块 156)
- 结论依据:原文权衡把分支枚举放在 Job 或放进 Pet 的依赖形状。
- 原始内容:Both options that we discussed in this chapter would work for PetSitter. The second option is closer to the domain model, since no changes are required within Job when we add new pets, and we have all the complex composition logic in