Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ScalaによるDDDライクなプロダクト開発
Search
Yoshinobu Wakamatsu
May 23, 2016
Technology
0
470
ScalaによるDDDライクなプロダクト開発
2016/5/23 モバイルファクトリーさんとの勉強会で話したスライド
Yoshinobu Wakamatsu
May 23, 2016
Tweet
Share
More Decks by Yoshinobu Wakamatsu
See All by Yoshinobu Wakamatsu
金融領域におけるサービス開発の進め方
yshnb
0
610
資産運用スタートアップの開発で採用した、PlayによるClean Arcitectureでの設計・開発事例
yshnb
5
910
ReactベースのSPA開発で開発者が気をつけたいSEOのお話
yshnb
2
1.6k
Fundsのアーキテクチャについて
yshnb
0
210
Applivの開発体制から考える、理想の開発体制とは?
yshnb
2
10k
Other Decks in Technology
See All in Technology
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
290
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
510
いざ、BSC討伐の旅
nikinusu
2
780
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
Terraform Stacks入門 #HashiTalks
msato
0
350
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
170
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
Featured
See All Featured
Scaling GitHub
holman
458
140k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Statistics for Hackers
jakevdp
796
220k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
A Modern Web Designer's Workflow
chriscoyier
693
190k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Docker and Python
trallard
40
3.1k
Transcript
4DBMBʹΑΔ%%%ϥΠΫͳ ϓϩμΫτ։ൃ φΠϧɾϞόΠϧϑΝΫτϦʔ߹ಉษڧձ φΠϧגࣜձࣾएদܚ৴
ࣗݾհ एদܚ৴ φΠϧגࣜձࣾΤϯδχΞ 5XJUUFSɾ(JUIVCZTIOC ʢ΄ͱΜͲ׆ಈͯ͠·ͤΜʣ ͜͜࠷ۙ4DBMBΛ͍ͬͯ·͢ WJNΛ͍ͬͯ·͢
ࠓճͷϓϩμΫτ։ൃʹ͍ͭͯ
ࠓճͷϓϩμΫτ։ൃͷ݅ • Ϗδωε্ͷཁٻ͕ൺֱతଟذʹΘͨΔ • ؔऀͷϩʔϧଟ͍ – ϓϩμΫτΦʔφʔɺΦϖϨʔλʔɺཧ෦ͳͲ • ظతͳӡ༻͕ݟࠐ·ΕΔ
͜ΕΒͷ݅Λߟྀͯ͠ υϝΠϯۦಈઃܭʢ%%%ʣΛ࠾༻
ࠓճͷʮυϝΠϯۦಈઃܭʯʹ͍ͭͯ • υϝΠϯۦಈઃܭͷίϯηϓτΛऔΓೖΕͯɺ ઃܭ։ൃΛ࣮ࢪ • ඞͣ͠ݪଇ௨ΓͰͳ͍ܗͰ υϝΠϯۦಈઃܭͷίϯηϓτΛ࠾༻
ͳͥ4DBMBͰ%%%ͳͷ͔ʁ • ࣮༻తͳγϯλοΫεͷ؆ܿ͞ – ϞσϧΛ࣮ʹམͱ͢ίετ͕͍ • ܕγεςϜ͕ڧྗ – ੩తܕ͚ʹΑΔܕ҆શੑ ϏδωεϩδοΫ͕ෳࡶͳέʔεͰޮՌత
– ϞσϧΛܕͰදݱ͢Δ͜ͱ͕Ͱ͖Δ
υϝΠϯۦಈઃܭͱ
υϝΠϯۦಈઃܭͱ ιϑτΣΞͷઃܭख๏Ͱ͋ΓɺʮෳࡶͳυϝΠ ϯͷઃܭɺϞσϧϕʔεͰߦ͏͖ʯͰ͋Γɺ ·ͨʮେͷιϑτΣΞϓϩδΣΫτͰɺγ εςϜΛ࣮͢ΔͨΊͷಛఆͷٕज़Ͱͳ͘ɺυ ϝΠϯͦͷͷͱυϝΠϯͷϩδοΫʹযΛஔ ͖͘ʯͰ͋Δͱ͢Δ CZ8JLJQFEJB
ʁʁʁ
͏গ͠Θ͔Γ͘͢
υϝΠϯۦಈͰͳ͍ઃܭͷྫ ࣮ݱ͍ͨ͠ػೳɾݟͨΛܾΊΔ ٕज़બఆઃܭΛߦ͍ɺ ۩ମతͳ࣮ٕज़ͰػೳΛ࣮ݱ͢Δ ͜ΕυϝΠϯͷຊ࣭͕Կͳͷ͔ʁΛ໌Β͔ʹ͓ͯ͠Βͣɺ υϝΠϯۦಈઃܭͰͳ͍
υϝΠϯۦಈઃܭʁ ϏδωεྖҬͷϢϏΩλεݴޠ ʢ౷ҰݴޠʣΛߏங ʮ࣮ݱ͍ͨ͜͠ͱʯʮ࣮ݱ͢Δ͜ͱʯΛ ϢϏΩλεݴޠͰදݱ ϢϏΩλεݴޠͰදݱ͞ΕͨυϝΠϯϞσϧΛ ۩ମతͳ࣮ٕज़Ͱ࣮͢Δ
ϢϏΩλεݴޠʹΑΔ υϝΠϯϞσϧ
ϓϩμΫτ։ൃʹ͓͚ΔݴޠͷִͨΓ ϓϩμΫτΦʔφʔ ։ൃऀ ΫϥΠΞϯτ ΫϥΠΞϯτ
ϓϩμΫτ։ൃʹ͓͚ΔݴޠͷִͨΓ ϓϩμΫτΦʔφʔ ։ൃऀ ΫϥΠΞϯτ ΫϥΠΞϯτ ʮΫϥΠΞϯτʯಉ͡ҙຯʁ
ϢϏΩλεݴޠͰ༻ޠΛ౷Ұ ༻ޠͷఆٛΛ໌֬ʹ͢Δ ސ٬ ͓٬༷ Ϗδωε্ͷΫϥΠΞϯτ ΫϥΠΞϯτ αʔόɾΫϥΠΞϯτϞσϧͷ ΫϥΠΞϯτʢٕज़༻ޠʣ • ౷ҰͷޠኮͰཁ݅ɾ༷ΛܾΊΔ
• ౷ҰޠኮͰද͞ΕͨϏδωε্ͷࣝΛϞσϧԽ͢Δ
౷ҰޠኮͰυϝΠϯͷࣝΛද͢ • ̍ͭͷʮސ٬ʯෳͷʮϓϩδΣΫτʯΛ࣋ͭ • ʮϢʔβʯʮϓϩδΣΫτʯ͝ͱ ʮݖݶʯΛมߋ͢Δ͜ͱ͕Ͱ͖Δ ʮϢʔβʯͱʁʮݖݶʯͱʁͳͲ͕ ໌֬ʹͳ͍ͬͯΔͷͰɺ ʮϢʔβʯʹର͢ΔೝࣝͷζϨੜ͡ͳ͘ͳΔ
υϝΠϯͷࣝΛϞσϧԽ 顧客 プロジェクト ϞσϧΛͲ͏දݱ͢Δ͔ʁͦ͜·ͰॏཁͰͳ͍ Ͳ͏͍͏ϞσϧͰ͋Δ͔ʁΛ νʔϜͷதͰڞ༗Ͱ͖͍ͯΔ͜ͱ͕ॏཁ ϞσϧԽͷྫ
υϝΠϯۦಈΛ࣮ݱ͢Δ ΞʔΩςΫνϟ
ΞʔΩςΫνϟͷཁٻ • υϝΠϯϞσϧ͕ओମʹͳΔ͖ – Ϟσϧ͕ಛఆͷ࣮ٕज़ʹґଘ͍͚ͯ͠ͳ͍ • ٕज़తͳؔ৺ࣄυϝΠϯͷؔ৺ࣄͱ ͞Ε͍ͯΔ͖
ҰൠతͳϨΠϠʔԽΞʔΩςΫνϟ Infrastructure Layer UI & Presenta1on Layer Applica1on Layer Domain
Layer
ҰൠతͳϨΠϠʔԽΞʔΩςΫνϟ Infrastructure Layer UI & Presenta1on Layer Applica1on Layer Domain
Layer υϝΠϯ͕ΠϯϑϥετϥΫνϟ ʢ۩ମతͳ࣮ٕज़ʣʹґଘͯ͠͠·͍ͬͯΔ
࠾༻ͨ͠ΞʔΩςΫνϟ Domain Layer Infrastructure Layer UI & Presenta1on Layer Applica1on
Layer
࠾༻ͨ͠ΞʔΩςΫνϟ Domain Layer Infrastructure Layer UI & Presenta1on Layer Applica1on
Layer υϝΠϯΛ࠷ԼҐͷϨΠϠʔ ΠϯϑϥετϥΫνϟͷར༻͕ඞཁͳՕॴ ͦͷΠϯλʔϑΣΠεΛఏڙ
࠾༻ͨ͠ΞʔΩςΫνϟ Domain Layer Infrastructure Layer UI & Presenta1on Layer Applica1on
Layer ΠϯϑϥετϥΫνϟ࠷্ҐͷϨΠϠʔʹ͠ ԼҐϨΠϠʔͷΠϯλʔϑΣΠεΛ࣮
ΞʔΩςΫνϟΛ࣮ݱ͢Δʹ • ηύϨʔτΠϯλʔϑΣΠε ۩ମతͳ࣮Λ༩͑Δඞཁ͕͋Δ • ޙ͔Β࣮Λ༩͑Δखஈ – %FQFOEFODZ*OKFDUJPO %*
– 4FSWJDF-PDBUPS – ͳͲ • ࠓճ%*Ͱ࣮Λఏڙˠ4DBMBͰʁ
4DBMBʹΑΔ੩త%* trait RepositoryRegistry { val fooRepository: Repo } // fooRepositoryΛ͏Ϋϥε
trait BarService { this: RepositoryRegistry => def doSomething = { fooRepository.fetch } } // ࣮Λ࣋ͭτϨΠτ trait RepositoryRegistryImpl { // Repo࣮ val fooRepository = Repo } // ࣮Λಋೖ class BerServiceImpl extends RepositoryRegistryImpl
4DBMBʹΑΔ੩త%* trait RepositoryRegistry { val fooRepository: Repo } // fooRepositoryΛ͏Ϋϥε
trait BarService { this: RepositoryRegistry => def doSomething = { fooRepository.fetch } } // ࣮Λ࣋ͭτϨΠτ trait RepositoryRegistryImpl { // Repo࣮ val fooRepository = Repo } // ࣮Λಋೖ class BerServiceImpl extends RepositoryRegistryImpl ͜ΕͨͩͷΠϯλʔϑΣΠεʢUSBJUʣ
4DBMBʹΑΔ੩త%* trait RepositoryRegistry { val fooRepository: Repo } // fooRepositoryΛ͏Ϋϥε
trait BarService { this: RepositoryRegistry => def doSomething = { fooRepository.fetch } } // ࣮Λ࣋ͭτϨΠτ trait RepositoryRegistryImpl { // Repo࣮ val fooRepository = Repo } // ࣮Λಋೖ class BerServiceImpl extends RepositoryRegistryImpl ࣗܕΞϊςʔγϣϯͰUSBJUͷґଘΛએݴ
4DBMBʹΑΔ੩త%* trait RepositoryRegistry { val fooRepository: Repo } // fooRepositoryΛ͏Ϋϥε
trait BarService { this: RepositoryRegistry => def doSomething = { fooRepository.fetch } } // ࣮Λ࣋ͭτϨΠτ trait RepositoryRegistryImpl { // Repo࣮ val fooRepository = Repo } // ࣮Λಋೖ class BerServiceImpl extends RepositoryRegistryImpl ͜͜Ͱ۩ମతͳ࣮Λ༩͍͑ͯΔ %*
4DBMBʹΑΔ੩త%* trait RepositoryRegistry { val fooRepository: Repo } // fooRepositoryΛ͏Ϋϥε
trait BarService { this: RepositoryRegistry => def doSomething = { fooRepository.fetch } } // ࣮Λ࣋ͭτϨΠτ trait RepositoryRegistryImpl { // Repo࣮ val fooRepository = Repo } // ࣮Λಋೖ class BerServiceImpl extends RepositoryRegistryImpl ࣮Λಋೖ͢Δલͷஈ֊Ͱ ґଘΛએݴͨ͠USBJUͷϝιου͕͑Δ
4DBMBʹΑΔϞσϧͷ࣮
ϞσϧΛઃܭɾ࣮ʹམͱ͢ • υϝΠϯͷ࣮ • υϝΠϯۦಈઃܭʹ͓͍ͯఆٛ͞Εͨಓ۩Λ ͍4DBMBͷίʔυͰදݱ͢Δ • %%%ͷಓ۩ – &OUJUZ
– 7BMVF0CKFDU – 4FSWJDF – 3FQPTJUPSZ – ͳͲ
ྫɿ7BMVF0CKFDUͷ࣮ • 7BMVF0CKFDU – Λදݱ͢ΔΦϒδΣΫτ – ࣗମʹυϝΠϯ্ͷҙຯΛ࣋ͨͤΔ • ྫɿՁ֨ʢ1SJDFʣ –
ʮԁʯʹؚ·ΕΔཁૉʮʯͱʮԁʯ – 1SJDFͷϞσϧ࣍ͷཁૉΛ࣋ͭ • WBMVF • DVSSFODZ+1:
+BWBʹΑΔ1SJDFΫϥε public class Price { public int value; // Ձ֨ͷ
public Currency currency; // ௨՟ Price(int value, Currency currency) { this.value = value; this.currency = currency; } } // PriceΦϒδΣΫτͷੜ new Price(100, new Currency(JPY))
4DBMBʹΑΔ1SJDFΫϥε case class Price(value: Int, currency: Currency) // case class
ʹΑΓ্هͷҰߦͰදݱग़དྷΔ // ͜Ε͚ͩͰ৽͍͠ΦϒδΣΫτΛੜՄೳ Price(100, JPY)
4DBMBʹΑΔ1SJDFΫϥε case class Price(value: Int, currency: Currency) // case class
ʹΑΓ্هͷҰߦͰදݱग़དྷΔ // ͜Ε͚ͩͰ৽͍͠ΦϒδΣΫτΛੜՄೳ Price(100, JPY) ϞσϧԽ͢Δ࣮ίετ͕ͱͯখ͍͞
ܕύϥϝʔλʹΑΔදݱ trait Tax case object IncludingTax extends Tax
// ੫ࠐ case object ExcludingTax extends Tax // ੫ൈ // ܕύϥϝʔλʢδΣωϦοΫʣʹΑͬͯදݱՄೳ // ATaxͷαϒܕ case class Price[A <: Tax](value: Int, currency: Currency) // 100ԁʢ੫ࠐʣͷදݱ Price[IncludingTax](100, JPY)
ܕύϥϝʔλʹΑΔදݱ trait Tax case object IncludingTax extends Tax
// ੫ࠐ case object ExcludingTax extends Tax // ੫ൈ // ܕύϥϝʔλʢδΣωϦοΫʣʹΑͬͯදݱՄೳ // ATaxͷαϒܕ case class Price[A <: Tax](value: Int, currency: Currency) // 100ԁʢ੫ࠐʣͷදݱ Price[IncludingTax](100, JPY) ੫ൈɾ੫ࠐΛܕύϥϝʔλʹΑͬͯදݱ
ܕύϥϝʔλʹΑΔදݱ // ͷՁ֨੫ࠐͰ͋Δ͜ͱ͕ܕͰදݱग़དྷΔ case class Product( name: String,
price: Price[IncludingTax] ) // ͷදݱྫ Product(“ίοϓຊ”, Price[IncludingTax](4968, JPY)) ͜ͷΑ͏ͳܗͰɺϞσϧΛ؆͔ܿͭܕ҆શʹ ίʔυʹམͱ͍ͯ͘͜͠ͱ͕Մೳ
·ͱΊ
4DBMBʹΑΔ%%%Ͳ͏ͳͷʁ • υϝΠϯۦಈઃܭʹ͓͚Δ4DBMBͷ࠾༻ ʢ࣮ίετɾදݱྗͷ؍ͰʣϝϦοτ͕େ͖͍ • ͨͩ͠ɺͲͷϓϩμΫτʹద͍ͯ͠ΔΘ͚Ͱͳ͍ – ྫ͑ɺϓϩτλΠϓతͳϓϩμΫτʹෆ͖ • ϓϩμΫτʹదͨ͠ઃܭख๏ΛऔΕ͍ͯΔ͔͕
࠷ऴతʹॏཁ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠