会员系统DSL 描述
会员系统DSL 描述
如花是一名架构师,对
如花加入会员团队后,和大家沟通了基于
从SubDomain 开始
如花开始


Domain User {
domainVisionStatement = "User domain to manage account, tags, profiles and payment profile."
Subdomain AccountDomain {
type = CORE_DOMAIN
domainVisionStatement = "Account domain to save sensitive data and authentication"
}
Subdomain UserTagDomain {
type = GENERIC_SUBDOMAIN
domainVisionStatement = "UserTag domain manage user's KV and Boolean tag"
}
Subdomain PaymentProfileDomain {
type = CORE_DOMAIN
domainVisionStatement = "User payment profile domain to manage credit/debit card, Alipay payment information"
}
Subdomain SnsProfileDomain {
type = CORE_DOMAIN
domainVisionStatement = "User Sns profile domain to manage user Sns profile for Weibo, Wechat, Facebook and Twitter."
}
Subdomain ProfilesDomain {
type = CORE_DOMAIN
domainVisionStatement = "User profiles domain to manage user basic profile, interest profile etc"
}
}
虽然目前我们还不知道对应的
注意,
Subdomain AccountDomain {
type = CORE_DOMAIN
domainVisionStatement = "Account domain to save sensitive data and authentication"
Entity Account {
long id
String nick
String mobile
String ^email
String name
String salt
String passwd
int status
Date createdAt
Date updatedAt
}
Service AccountService {
void updatePassword(long accountId, String oldPassword, String newPassword);
void resetPassword(long acountId);
boolean authByEmail(String email, String password);
boolean authBySmsCode(String mobile, String code);
}
}
Context Map
既然是描述各个

ContextMap UserContextMap {
type = SYSTEM_LANDSCAPE
state = TO_BE
contains AccountContext
contains UserTagContext
contains PaymentProfileContext
contains SnsProfileContext
contains ProfilesContext
contains UserLoginContext
contains UserRegistrationContext
UserLoginContext [D]<-[U] AccountContext {
implementationTechnology = "RSocket"
exposedAggregates = AccountFacadeAggregate
}
ProfilesContext [D]<-[U] UserTagContext {
implementationTechnology = "RSocket"
exposedAggregates = UserTags
}
UserRegistrationContext [D,C]<-[U,S] UserTagContext {
implementationTechnology = "RSocket"
exposedAggregates = UserTags
}
UserRegistrationContext [D,C]<-[U,S] SnsProfileContext {
implementationTechnology = "RSocket"
}
}
大家可以看到
BoundedContext
在
BoundedContext AccountContext implements AccountDomain {
type = APPLICATION
domainVisionStatement = "Managing account basic data"
implementationTechnology = "Kotlin, Spring Boot, MySQL, Memcached"
responsibilities = "Account", "Authentication"
Aggregate AccountFacadeAggregate {
ValueObject AccountDTO {
long id
String nick
String name
int status
Date createdAt
def toJson();
}
/* AccountFacade as Application Service */
Service AccountFacade {
@AccountDTO findById(Integer id);
}
}
Aggregate Accounts {
Entity Account {
long id
String nick
String mobile
String ^email
String name
String salt
String passwd
int status
Date createdAt
Date updatedAt
}
}
}
这里对
-
BoundedContext 的名称,这个不用说啦,这个和ContextMap 中名称一致。 -
implements AccountDomain:表示要实现哪一个
SubDomain ,我们都知道一个Subdomain 可能会包含多个BoundedContext ,这些BoundedContext 配合起来完成Subdomain 的业务需求。ContextMap 还提供refines ,来表示BoundedContext 要实现一些user case ,官方文档有对应的说明。 -
BoundedContext 的属性字段:type 表示类型,如APPLICATION 、SYSTEM 等。domainVisionStatement 描述一下BoundedContext 的职责。implementationTechnology 表示具体的技术,前面我们说到BoundedContext 已经涉及具体的应用和系统等,所以要说明对应的技术方案实现,核心的部分描述一下就可以。responsibilities 表示BoundedContext 的职责列表,这里只需要关键字就可以,如Account 要负责安全验证等。 -
AccountFacadeAggregate: 表示提供给外部调用的聚合,这里DTO 的对象定义、服务接口的定义等。 -
Aggregate Accounts:这个表示
BoundedContext 内部的聚合,如entity 、value object、service 等。这里说明一下,DDD 中的那个Aggregate 是entity ,value object 的聚合对象,而ContextMapper 中的Aggregate 表示为一些资源的集合,如Service 集合等。
其它特性
UserStory
这个
UserStory Customers {
As a "Login User"
I want to update a "Avatar"
I want to update an "Address"
so that "I can manage the personal data."
}
UseCase
UseCase UC1_Example {
actor = "Insurance Employee"
interactions = create a "Customer", update a "Customer", "offer" a "Contract"
benefit = "I am able to manage the customers data and offer them insurance contracts."
}
在
Aggregate Contract {
useCases = UC1_Example, UC2_Example
}