项目作者: gnodux

项目描述 :
基于PlantUML定制的4色领域模型建模工具
高级语言:
项目地址: git://github.com/gnodux/coloruml.git
创建时间: 2019-09-18T10:13:55Z
项目社区:https://github.com/gnodux/coloruml

开源协议:

下载


基于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

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

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

例如一个简单的示例:

Book Store

  1. @startuml Book Store sample
  2. '!include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
  3. !include ../coloruml.puml
  4. 'left_to_right
  5. moment(订单,Order){
  6. int OrderId
  7. int Status
  8. }
  9. moment(Bill)
  10. moment(Delivery)
  11. thing(Book)
  12. desc(Comments)
  13. role(Customer)
  14. thing(Employee){
  15. String Name
  16. Date Birthday
  17. int Status()
  18. }
  19. thing(Author)
  20. role(Courier)
  21. role(Accounting)
  22. Courier from(Employee)
  23. Accounting from(Employee)
  24. Book contains(Comments)
  25. Book has_d(Author)
  26. Order contains(Bill)
  27. Order contains(Delivery)
  28. Order has(Book)
  29. Bill has(Accounting)
  30. Delivery has(Courier)
  31. Customer has(Order)
  32. Customer has(Comments)
  33. Bill layout_u(Delivery)
  34. @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预处理关键字引入模型

  1. !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 角色
  1. @startuml example
  2. !include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
  3. moment(订单,Order)
  4. thing(书,Book)
  5. @enduml

example

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

  1. @startuml example
  2. !include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
  3. moment(订单,Order)
  4. thing(书,Book){
  5. string Title
  6. int AuthorId
  7. string ISBN
  8. }
  9. @enduml

Field example

领域模型的关系

主要包含以下关系:

  • has: 可能包含
  • contains: 父子关系
  • rel: 引用

描述关系的时候使用has[_r/l/u/d],其中r(ight)/l(eft)/u(p)/d(own)可以进行简单布局。
contains和rel类似。 例如

  1. @startuml example
  2. !include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
  3. moment(订单,Order)
  4. thing(书,Book){
  5. string Title
  6. int AuthorId
  7. string ISBN
  8. }
  9. Order has(Book)
  10. @enduml

relation example

更复杂的管理参考 bookstore.puml

其他

备注:可以给领域模型添加备注或说明

  1. @startuml example
  2. !include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
  3. moment(订单,Order)
  4. note right of Order: 订单对象是有状态的
  5. note left of Order
  6. ===订单对象流转说明
  7. * 订单状态包含...
  8. * 订单审批流程...
  9. end note
  10. @enduml

notes examples

预制函数

  • hand_write():手写
  • legend(): 图例
  • hard_line(): 直线连接
  • left_to_right() :从左到右布局
  • title : 标题
  1. @startuml Book Store sample
  2. !include https://raw.githubusercontent.com/gnodux/coloruml/master/coloruml.puml
  3. title 书店简单领域模型图
  4. left_to_right()
  5. hand_write()
  6. hard_line()
  7. legend()
  8. moment(订单,Order){
  9. int OrderId
  10. int Status
  11. }
  12. moment(Bill)
  13. moment(Delivery)
  14. thing(Book)
  15. desc(Comments)
  16. role(Customer)
  17. thing(Employee){
  18. String Name
  19. Date Birthday
  20. int Status()
  21. }
  22. thing(Author)
  23. role(Courier)
  24. role(Accounting)
  25. Courier from(Employee)
  26. Accounting from(Employee)
  27. Book contains(Comments)
  28. Book has_d(Author)
  29. Order contains(Bill)
  30. Order contains(Delivery)
  31. Order has(Book)
  32. Bill has(Accounting)
  33. Delivery has(Courier)
  34. Customer has(Order)
  35. Customer has(Comments)
  36. Bill layout_u(Delivery)
  37. @enduml

book store hand written