Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ドメイン駆動設計とイミュータブルなクラス設計
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
増田 亨
PRO
November 24, 2021
Programming
12k
10
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ドメイン駆動設計とイミュータブルなクラス設計
クラスをイミュータブルに設計するパターンの紹介
・閉じた操作
・withメソッド
・イベントリポジトリ&集約ファクトリ
増田 亨
PRO
November 24, 2021
More Decks by 増田 亨
See All by 増田 亨
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
12
6.1k
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
18
8.5k
データエンジニアリングとドメイン駆動設計
masuda220
PRO
17
3.4k
AI 時代のソフトウェア設計の学び方
masuda220
PRO
31
15k
SCSD:事業価値を生み出すソフトウェア開発の実践技法
masuda220
PRO
4
390
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
10
1.6k
競争優位を生み出す戦略的内製開発の実践技法
masuda220
PRO
5
880
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
30
25k
乱雑なコードの整理から学ぶ設計の初歩
masuda220
PRO
38
18k
Other Decks in Programming
See All in Programming
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
ジョジョの世界をXRで再現する
mofurune
0
160
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
4
3.2k
速習iPhone Duo対応
yuukiw00w
2
990
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
480
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
260
JIS keyboard support in Omarchy
lef237
0
110
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
golang-bob.pdf
iwatsukayura
0
130
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
590
Music & Morning Musume
bryan
48
7.4k
Paper Plane (Part 1)
katiecoart
PRO
2
12k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
520
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
930
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Designing for humans not robots
tammielis
254
26k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Building an army of robots
kneath
307
47k
Transcript
ドメイン駆動設計と イミュターブルな設計 2021年11月24日 有限会社システム設計 増田
『ドメイン駆動設計』のエッセンス 第3章 モデル駆動設計(モデルと実装を一致させる) 第10章 しなやかな設計(変更を楽で安全にする設計パターン) 第15章 蒸留(コアドメインに集中する)
クラス設計の方針の違い できれば イミュータブルにする できるだけ イミュータブルにする かならず イミュータブルにする
クラス設計の方針の違い できれば イミュータブルにする できるだけ イミュータブルにする かならず イミュータブルにする 値オブジェクト 副作用のない関数 閉じた操作
宣言的な設計スタイル ドメイン・プリミティブ 部分的不変エンティティ エンティティスナップショット エンティティリレー 値オブジェクト コレクションオブジェクト 区分オブジェクト 口座・履歴パターン
イミュータブルなクラスの設計パターン 閉じた操作 withメソッド (setterの代替) イベントリポジトリ・集約ファクトリ
閉じた操作 操作(メソッド)の引数の型と返す値の型が、そのクラスの型に閉じる String#concat(String other) : String BigDecimal#add(BigDecimal other) : BigDecimal
Money#add(Money other) : Money Quantity#add(Quantity other) : Quantity Set#union(Set other) : Set Map#merge(Map other) : Map イミュータブルな値オブジェクトの基本パターン
withメソッドパターン イミュターブルなクラスを設計する時のsetterの代替パターン 不変なオブジェクトを元に別インスタンスを作成する LocaDate#withMoth(int month) : LocalDate LocalDate#withYear(int year) :
LocalDate SalesOrder#add(ItemLine itemLine) : SalesOrder //別インスタンス イミュータブルな集約への応用例(『ドメイン駆動設計』10章) SharePie#比例配分with(long 配分する総額) : SharePie //新たな配分構成
イベントリポジトリ・集約ファクトリ データベース イベントリポジトリ 記録 発生した事実 集約ファクトリ 構築 集約のインスタンス イベントストアから導出 エンティティスナップショット(キャッシュ)
スナップショット+導出 事実の記録と集約の構築を非対称にする(集約を永続化しない) 集約を変更する時は、まず事実を記録してから集約インスタンスを生成する 目的ごとに異なる集約 データ(事実)と ロジック(計算判断)を カプセル化