这个项目是在PlantUML的基础上的定制,支持快速绘制领域模型图.
结合C4 Model,基本可以实现从业务到技术架构的完整设计,C4 model参考另外一个项目: C4-PlantUML
PlantUML是一个开源项目,支持"写文字"的方式快速绘制多种图形UML及非UML图形。 具体语法可以参考:PlantUML
4色领域模型的概念来自 Java Modeling In Color With UML
Peter Coad提出的几类基本元模型对于实际进行建模工作有着非比寻常的指导价值——当大多数人在分析业务领域模型时,Peter Coad在分析业务领域的元模型,其“鬼才”由此可见一斑。至于“带颜色的UML”,无非是对元模型的一种直观描述而已。对于面向对象(而非面向用例)的企业应用业务建模,这本“小书”便是首屈一指的最佳实践指南.
在这本小书里,archetype 被分为:
- Moment-Interval
- Role
- Description
- "Party,Place, or Thing"
4种类型。通过对对象的分类,快速抓住关键业务控制点。
领域模型建模的相关概念及链接:
在绘制领域模型图的时候,直接引用:
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
例如一个简单的示例:
@startuml Book Store sample
'!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
!include ../coloruml.puml
'left_to_right
moment(订单,Order){
int OrderId
int Status
}
moment(Bill)
moment(Delivery)
thing(Book)
desc(Comments)
role(Customer)
thing(Employee){
String Name
Date Birthday
int Status()
}
thing(Author)
role(Courier)
role(Accounting)
Courier from(Employee)
Accounting from(Employee)
Book contains(Comments)
Book has_d(Author)
Order contains(Bill)
Order contains(Delivery)
Order has(Book)
Bill has(Accounting)
Delivery has(Courier)
Customer has(Order)
Customer has(Comments)
Bill layout_u(Delivery)
@enduml
- 在JetBrains 下载IntelliJ IDEA Download IntelliJ IDEA
- 安装Plugins: PlantUML Integration / PlantUML Syntax Checker
使用plantuml include
预处理关键字引入模型
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
领域对象的绘制比较简单,使用封装的函数即可,以4色领域模型为例:
- moment(label,alias)|{}: moment-of-interval对象
- thing/party/place(label,alias)|{} : thing/party/place
- desc(label,alias)|{}: description描述对象
- role(label,alias)|{}: role 角色
@startuml example
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
moment(订单,Order)
thing(书,Book)
@enduml
接下来我们为领域对象添加一些属性和方法:
@startuml example
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
moment(订单,Order)
thing(书,Book){
string Title
int AuthorId
string ISBN
}
@enduml
主要包含以下关系:
- has: 可能包含
- contains: 父子关系
- rel: 引用
描述关系的时候使用has[_r/l/u/d],其中r(ight)/l(eft)/u(p)/d(own)可以进行简单布局。 contains和rel类似。 例如
@startuml example
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
moment(订单,Order)
thing(书,Book){
string Title
int AuthorId
string ISBN
}
Order has(Book)
@enduml
更复杂的管理参考 bookstore.puml
@startuml example
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
moment(订单,Order)
note right of Order: 订单对象是有状态的
note left of Order
===订单对象流转说明
* 订单状态包含...
* 订单审批流程...
end note
@enduml
- hand_write():手写
- legend(): 图例
- hard_line(): 直线连接
- left_to_right() :从左到右布局
- title : 标题
@startuml Book Store sample
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
title 书店简单领域模型图
left_to_right()
hand_write()
hard_line()
legend()
moment(订单,Order){
int OrderId
int Status
}
moment(Bill)
moment(Delivery)
thing(Book)
desc(Comments)
role(Customer)
thing(Employee){
String Name
Date Birthday
int Status()
}
thing(Author)
role(Courier)
role(Accounting)
Courier from(Employee)
Accounting from(Employee)
Book contains(Comments)
Book has_d(Author)
Order contains(Bill)
Order contains(Delivery)
Order has(Book)
Bill has(Accounting)
Delivery has(Courier)
Customer has(Order)
Customer has(Comments)
Bill layout_u(Delivery)
@enduml