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
450
ScalaによるDDDライクなプロダクト開発
2016/5/23 モバイルファクトリーさんとの勉強会で話したスライド
Yoshinobu Wakamatsu
May 23, 2016
Tweet
Share
More Decks by Yoshinobu Wakamatsu
See All by Yoshinobu Wakamatsu
金融領域におけるサービス開発の進め方
yshnb
0
570
資産運用スタートアップの開発で採用した、PlayによるClean Arcitectureでの設計・開発事例
yshnb
5
880
ReactベースのSPA開発で開発者が気をつけたいSEOのお話
yshnb
2
1.4k
Fundsのアーキテクチャについて
yshnb
0
190
Applivの開発体制から考える、理想の開発体制とは?
yshnb
2
10k
Other Decks in Technology
See All in Technology
Datadog Cloud SIEMを使ってAWS環境の脅威を可視化した話/lifeistech-datadog-cloud-siem
gidajun
0
480
成長期に歩みを止めないための創業期の開発文化形成
mayah
6
420
楽しくGoを学び合う、LayerXの勉強会文化 / LayerX's study culture of having fun and learning Go together
ar_tama
2
350
Flutter研修【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
160
フルリモートワークはエンジニアの夢を叶えたか? #cm_odyssey
mamohacy
2
600
累計ダウンロード数1億8000万を超えるアプリケーションプラットフォームのレガシーシステム脱却とモダン化への道
kmitsuhashi
0
120
テストケースの自動生成に生成AIの導入を試みた話と生成AIによる今後の期待
shift_evolve
0
180
Azure Pipelinesを使用したCICDベースラインアーキテクチャ実践
yuriemori
0
190
AI研修【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
130
スタートアップにおける組織設計とスクラムの長期戦略 / Scrum Fest Kanazawa 2024
yoshikiiida
13
3.6k
LLMアプリケーションの評価の実践と課題 ~PharmaXにおける今後の展望~
pharma_x_tech
2
160
What if...? 처음부터 다시 LLM 어플리케이션을 개발한다면
huffon
0
1k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
23
1.9k
Building Flexible Design Systems
yeseniaperezcruz
323
37k
Why Our Code Smells
bkeepers
PRO
332
56k
Designing for humans not robots
tammielis
247
25k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
129
32k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
19k
Being A Developer After 40
akosma
72
580k
Embracing the Ebb and Flow
colly
81
4.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
42
2.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
13
430
Six Lessons from altMBA
skipperchong
24
3.2k
Making the Leap to Tech Lead
cromwellryan
127
8.7k
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ͷ࠾༻ ʢ࣮ίετɾදݱྗͷ؍ͰʣϝϦοτ͕େ͖͍ • ͨͩ͠ɺͲͷϓϩμΫτʹద͍ͯ͠ΔΘ͚Ͱͳ͍ – ྫ͑ɺϓϩτλΠϓతͳϓϩμΫτʹෆ͖ • ϓϩμΫτʹదͨ͠ઃܭख๏ΛऔΕ͍ͯΔ͔͕
࠷ऴతʹॏཁ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠