环境准备,开发约定和架构说明开发环境和技术选型对象命名约定架构选择战术设计分析方法交易域业务流程售卖机扫码支付购物 战术分析货柜机免密购物 战术分析上下文交互图代码搭建实体和值对象领域对象构造资源库与持久化聚合领域服务应用层领域事件事件风暴建模法
环境准备,开发约定和架构说明
开发环境和技术选型
对象命名约定
架构选择
交易上下文局部框图
战术设计分析方法
交易域业务流程
售卖机扫码支付购物 战术分析
货柜机免密购物 战术分析
对应战术设计中的复杂交互,通过时序图描述
上下文交互图
代码搭建
代码搭建实体和值对象
- 实体: 主要由标识定义的对象被称作ENTITY
- 值对象: 用于描述领域的某个方面而本身没有概念标识的对象称为值对象
需要以ID来跟踪状态变化的对象为实体,否则为值对象
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#d1e3a0','textColor':'#ffffff','loopTextColor':'#ffffff'}}}%% flowchart LR 对象的相等性-->标识符相等性 标识符相等性---身份证号标识公民 对象的相等性-->引用指针符相等性 对象的相等性-->属性相等性 属性相等性---通过品牌,版本,容量和制式判断是否同一手机
库存商品值对象
/** * @author: yoda * @description: 库存商品 */ public final class StockedCommodity { private final String commodityId; private final String name; private final String imageUrl; private final BigDecimal price; private final int count; public StockedCommodity(String commodityId, String name, String imageUrl, BigDecimal price, int count) { this.commodityId = commodityId; this.name = name; this.imageUrl = imageUrl; this.price = price; this.count = count; } public StockedCommodity(StockedCommodity copy) { this.commodityId = copy.commodityId; this.price = copy.price; this.count = copy.count; this.imageUrl = copy.imageUrl; this.name = copy.name; } public String getCommodityId() { return commodityId; } public String getName() { return name; } public String getImageUrl() { return imageUrl; } public BigDecimal getPrice() { return price; } public int getCount() { return count; } public StockedCommodity withCount(int count) { StockedCommodity ret = new StockedCommodity(this.commodityId, this.name, this.imageUrl, this.price, count); return ret; } @Override public boolean equals(Object other) { if (other == null || this.getClass() != other.getClass()) { return false; } StockedCommodity commodity = (StockedCommodity) other; return this.commodityId.equals(commodity.commodityId) && this.name.equals(commodity.name) && this.imageUrl.equals(commodity.imageUrl) && this.count == commodity.count; } @Override public int hashCode() { return MathUtil.HASH_MAGIC_NUMBER + this.commodityId.hashCode() + this.name.hashCode() + this.imageUrl.hashCode() + this.count; } public static Builder Builder() { return new Builder(); } public static class Builder { private String commodityId; private String name; private String imageUrl; private BigDecimal price; private int count; public Builder commodityId(String commodityId) { this.commodityId = commodityId; return this; } public Builder name(String name) { this.name = name; return this; } public Builder imageUrl(String imageUrl) { this.imageUrl = imageUrl; return this; } public Builder price(BigDecimal price) { this.price = price; return this; } public Builder count(int count) { this.count = count; return this; } public StockedCommodity build() { return new StockedCommodity(this.commodityId, this.name, this.imageUrl, this.price, this.count); } } }
领域对象构造
可以使用builder模式