Skip to content

基于PlantUML定制的4色领域模型建模工具

Notifications You must be signed in to change notification settings

gnodux/coloruml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

基于PlantUML 的4色 领域模型建模

coloruml

这个项目是在PlantUML的基础上的定制,支持快速绘制领域模型图.

结合C4 Model,基本可以实现从业务到技术架构的完整设计,C4 model参考另外一个项目: C4-PlantUML

PlantUML是一个开源项目,支持"写文字"的方式快速绘制多种图形UML及非UML图形。 具体语法可以参考:PlantUML

关于4色领域模型建模

4色领域模型的概念来自 Java Modeling In Color With UML

Peter Coad提出的几类基本元模型对于实际进行建模工作有着非比寻常的指导价值——当大多数人在分析业务领域模型时,Peter Coad在分析业务领域的元模型,其“鬼才”由此可见一斑。至于“带颜色的UML”,无非是对元模型的一种直观描述而已。对于面向对象(而非面向用例)的企业应用业务建模,这本“小书”便是首屈一指的最佳实践指南.

在这本小书里,archetype 被分为:

  • Moment-Interval
  • Role
  • Description
  • "Party,Place, or Thing"

4种类型。通过对对象的分类,快速抓住关键业务控制点。

领域模型建模的相关概念及链接:

Getting start

在绘制领域模型图的时候,直接引用:

!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml

例如一个简单的示例:

Book Store

@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

Book Store

IntelliJ IDEA 集成

IntelliJ IDEA

  • 在JetBrains 下载IntelliJ IDEA Download IntelliJ IDEA
  • 安装Plugins: PlantUML Integration / PlantUML Syntax Checker

Visual studio code

安装 PlantUML extension

开始绘制你的领域模型

引入定义模型定义

使用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

example

接下来我们为领域对象添加一些属性和方法:

@startuml example
!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
moment(订单,Order)
thing(,Book){
    string Title
    int AuthorId
    string ISBN
}
@enduml

Field example

领域模型的关系

主要包含以下关系:

  • 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

relation example

更复杂的管理参考 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

notes examples

预制函数

  • 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

book store hand written

About

基于PlantUML定制的4色领域模型建模工具

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages