这篇文章接下来我们要谈谈《 企业应用架构模式- Martin Fowler 》这本书中所提 domain 的三种 patterns 的第二种『 Domain Model 』。
这是我从书中,自已提出的想法,我认为 domain model 为 :
将每个业务领域都定义成个实体,并且创建一个这些实体的关系网,然後每个实体中都有所谓的资料与行为。
我个人是为了 OO 算是是一种 domain model 的开发方式,然後 domain model class 基本上要包含 :
然後在书中有提到两种风格 :
以上两种风格的就在於,一个适合简单,一个适合复杂…… 就是这样。其中『 Active Record 』与『 Data Mapper 』在之後的文章会提到,它是在 3-tier 的资料层。
Anemic domain model
// Transaction Script
class CartService{
async checkout(){
// 取出购物车要结帐的商品
const products = this.cart.items
// 建立订单
const order = await orderDao.create(orderBody)
// 建立付款记录
const payment = await paymentDao.create(paymentBody)
// 建立发票
const invoice = await invoiceDao.create(invoiceBody)
}
}
// Domain Model
class Cart{
id: String
items: Product[]
async addItem(product: Product){
this.items.push(product)
}
async chekcout(){
}
}
class Order{
id: string
products: Product[]
construct(productDao:ProductDao){
this.productDao = productDao
}
async chekcout(){
this.productDao.save({
products
})
return this.id
}
}
class Payment{
async checkout(){
}
}
<<: 【把玩Azure DevOps】Day15 Pipeline与Artifacts应用:覆写C#专案属性资讯(上传nuget package成功)
>>: Day 12 - OOP 初探 (2) - Class
此篇为番外,为选入本篇的原因为 Jest 的功能与单元测试的方式多元且复杂,此篇仅能做初步的介绍,...
本篇来介绍 v-on 指令的特别之处,使用 JavaScript 撰写一个事件处理,除了 DOM 的...
上一篇我们统整了 NodeTransforms 里各个 methods 的用法以及参数介绍, 传送...
※Markdown语法 - 粗体字体呈现方式※ 第一种: <html> <h1&g...
Unity 开发 https://wolkesau.medium.com/unity-开发-7ddb...