Vũ Nhật Minh / @dtvd88
About me
Domain-Driven Design
DDD approach for Microservices architecture
+α
Vũ Nhật Minh
Oracle/PHP/Python/Scala backend engineer
Private:
Front-End Tech, UI/UX
Creator of Rainbow Stream
Writer at KTMT blog & admin at Kipalog.com
More info
About me
Domain-Driven Design
DDD approach for Microservices architecture
+α
Commit to use the language in everywhere
All communication form: speech, writing, diagrams ...
In the code later
Communicate with domain experts and find keywords
Developers can think about keyword as classes in OOP
User |
---|
UserID |
Name |
FacebookURL |
TwitterURL |
GithubURL |
User |
---|
UserID |
Name |
SocialProfile |
Social Profile |
---|
Github |
Entity
Value Object
Identity
// Entities with same id is considered the same.
class User(val userId: Int, val name: String, val profile: SocialProfile) {
def equals(other: User): Boolean = {
userId == other.userId
}
}
// Value Objects with same value is considered the same.
class SocialProfile(val facebookURL: String,
val twitterURL: String,
val githubURL: String) {
def equals(other: SocialProfile): Boolean = {
facebookURL == other.facebookURL &&
twitterURL == other.twitterURL &&
githubURL == other.twitterURL
}
}
class Saiyan(val name: String, val age: Int)
// Service provide a method to perform an operation
def fusionDance(left: Saiyan, right: Saiyan): Saiyan = {
new Saiyan(left.name + right.name, math.min(left.age,right.age))
}
User |
---|
UserID |
Name |
SocialProfile |
Social Profile |
---|
GIthub |
Contact Info |
---|
PhoneNumber |
EmailAddress |
Root Entity
Repository commonly refers to a storage location, often for safety or preservation.
Wikipedia
In DDD, Repository is more like a "facade" to data store (Database, cache ...)
Repository hold references to root Entity of Aggregates.
Repository != DAL (Data Access Layer)
PostRepository |
---|
findPost(cond) |
newPost() |
updatePost() |
... |
Post |
---|
postId |
title |
content |
Post |
---|
postId |
title |
content |
Post |
---|
postId |
title |
content |
Search Query |
---|
Search Cond |
---|
findPost(cond)
posts list
Repository
PostRepository |
---|
findPost(cond) |
newPost() |
updatePost() |
... |
Post |
---|
postId |
title |
content |
Post |
---|
postId |
title |
content |
Post |
---|
postId |
title |
content |
Search Query |
---|
Search Cond |
---|
findPost(cond)
posts list
Entity or Value Object ?
About me
Domain Driven Design
DDD approach for Microservices architecture
+α
There are advanced topics
Bounded Context
Context Map
Shared Kernel
Anticorruption Layer
Separate Ways
Open Host Service
Read Eric Evan's book and the online sumary version ...
until it make sense :)
About me
Domain Driven Design
DDD approach for Microservices architecture
+α