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初心者は◯◯◯にメソッドを生やしたいと考えた / Pre-ScalaMatsuri ...
Search
集約のエンティティ
August 30, 2020
Programming
3
2.6k
Scala初心者は◯◯◯にメソッドを生やしたいと考えた / Pre-ScalaMatsuri 2020
2020年8月30日に開催されたプレScalaMatsuriのLightning Talk発表資料です
https://scalaconfjp.doorkeeper.jp/events/110045
集約のエンティティ
August 30, 2020
Tweet
Share
More Decks by 集約のエンティティ
See All by 集約のエンティティ
組織を強くするPdMのマインド / PMHub vol.2
pictiny
5
780
戦略的DDDは重いのか? / Is strategic DDD heavy?
pictiny
4
2.9k
戦略的DDDを実践するための跳躍力 / OOC 2024
pictiny
9
10k
どうしてこうなった命名集 ~🔥編~ / OOC 2024 LT
pictiny
7
4.9k
おかしな名前 ~ 🔥編 ~ / Strange Name
pictiny
1
310
ドローンの会社は生成AIをどう活用するか / Generative AI Bounenkai 2023
pictiny
0
460
日報には"今日の一番大きな成果"を書こう / Kichijoji.pm 34
pictiny
1
1.2k
Scalaの現場から学ぶ設計:座談会 / genba sekkei vol 2
pictiny
0
690
Scalaの現場から学ぶ設計 告知 / genba sekkei vol.2 announce
pictiny
1
180
Other Decks in Programming
See All in Programming
私の後悔をAWS DMSで解決した話
hiramax
4
150
Langfuseと歩む生成AI活用推進
licux
3
300
あのころの iPod を どうにか再生させたい
orumin
2
2.5k
Claude Codeで挑むOSSコントリビュート
eycjur
0
180
【第4回】関東Kaggler会「Kaggleは執筆に役立つ」
mipypf
0
880
Jakarta EE Core Profile and Helidon - Speed, Simplicity, and AI Integration
ivargrimstad
0
210
一人でAIプロダクトを作るための工夫 〜技術選定・開発プロセス編〜 / I want AI to work harder
rkaga
13
2.8k
フロントエンドのmonorepo化と責務分離のリアーキテクト
kajitack
2
140
MLH State of the League: 2026 Season
theycallmeswift
0
160
Oracle Database Technology Night 92 Database Connection control FAN-AC
oracle4engineer
PRO
1
220
ライブ配信サービスの インフラのジレンマ -マルチクラウドに至ったワケ-
mirrativ
2
270
Google I/O recap web編 大分Web祭り2025
kponda
0
2.9k
Featured
See All Featured
Music & Morning Musume
bryan
46
6.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Visualization
eitanlees
147
16k
Designing for humans not robots
tammielis
253
25k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
How to Ace a Technical Interview
jacobian
279
23k
The Cost Of JavaScript in 2023
addyosmani
53
8.8k
RailsConf 2023
tenderlove
30
1.2k
A Modern Web Designer's Workflow
chriscoyier
695
190k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Transcript
!QJDUJOZ 1SF4DBMB.BUTVSJ -JHIUOJOH5BML 4DBMBॳ৺ऀ ̋̋̋ʹϝιουΛ ੜ͍ͨ͠ͱߟ͑ͨ
2020.08.30 2
2020.08.30 3 4DBMBະܦݧͰΞϧϓೖࣾ 4DBMBྺ
2020.02.16 4 ςΫϊϩδʔͷྗͰ اۀͷܦࡁ׆ಈΛ ࢧ͑ɺ֦ு͢Δɻ
2020.08.30 5 ʮαϒεΫϦϓγϣϯϏδωεʹ͓͚Δ શۀΛҰؾ௨؏ͰΧόʔʯ ɾϓϥΠγϯά ɾཧ ɾސ٬ཧ ɾܖཧ ɾٻॻͷൃߦˍૹ ɾΫϨδοτΧʔυܾࡁ
ɾ֤छσʔλੳ ɾ༁ొɺձܭॲཧ ɹɹɹɹɹɹɹɹɹɹɹetc…
2020.02.16 6
2020.02.16 7 %%%
2020.08.30 8 Ξϧϓɺ%%%ͬͯΔΑ ɹɹɹɹɹɹɹαϒεΫϦϓγϣϯྖҬͷ4BB4 ෳࡶ͕ඇৗʹߴ͍ ͦͷͨΊ։ൃॳظ͔Β%%%Λಋೖ શࣾతʹ࣮ફ
2020.08.30 9 ͔͜͜Βࠓͷ ˞ίʔυαϯϓϧͰ͢
2020.08.30 10 ར༻υϝΠϯ ٻରͱͳΔར༻ظؒΛநԽͨ͠ར༻ΦϒδΣΫτ 70 case class Availability ( startAt:
LocalDate, // ར༻։࢝ endAt: LocalDate, // ར༻ऴྃ billingDate: LocalDate, // ٻ status: AvailabilityStatus // εςʔλε )
2020.08.30 11 ྫɿܞଳճઢͷܖ ֤݄ͷར༻͝ͱʹٻ͕ൃੜ͢Δ ܖͰճઢΛܖ͢Δͱɺϲ݄ͷར༻͕ੜ͡Δ ٻ͕ྃ͢Δͱରͷར༻ͷঢ়ଶ͕ ʮະٻʯ͔ΒʮٻࡁΈʯʹͳΔ
2020.08.30 12 ܖυϝΠϯ ܖΛநԽͨ͠ܖΦϒδΣΫτ &OUJUZ ར༻Λෳ࣋ͭ case class Contract (
id: ContractId, // ܖID availabilities: Seq[Availability], // ར༻ status: ContractStatus, // εςʔλε pricing: …, // ྉۚઃఆ … )
2020.08.30 13 ະٻͷར༻ΛٻΊΔ ར༻ͷεςʔλε͕ະٻͳͷ case class Contract (…) { def
unBilledAvailabilities: Seq[Availability] = availabilities.filter(_.status = UnBilled) // ະٻͷར༻ }
2020.08.30 14 ࣍ճͷٻΛٻΊΔ ະٻͷར༻ͷ͏ͪɺٻ͕࠷͍ۙͷ case class Contract (…) { def
nextBillingDate(today: LocalDate): LocalDate = availabilities.filter(_.status = UnBilled) // ະٻͷར༻Ͱ .filter(_.billingDate > today) // ٻ͕ࠓΑΓະདྷͰ .minBy(_.billingDate.toEpochDay) // ٻ͕࠷աڈͷͷ .billingDate }
2020.08.30 15 ࠓٻ͢Δར༻ΛٻΊΔ ະٻͷར༻ͷ͏ͪɺٻ͕ࠓͷͷ case class Contract (…) { def
shouldCreateBilling(today: LocalDate): Seq[Availability] = availabilities.filter(_.status = UnBilled) // ະٻͷར༻Ͱ .filter(_.billingDate = today) // ٻ͕ࠓ }
2020.08.30 16
2020.08.30 17 ͍ͭಉ͡pMUFSͯ͠ͳ͍ʁ
2020.08.30 18 ϦϑΝΫλ ར༻͕ܖʹ͔͠ొ͠ͳ͍ͳΒ͜ΕͰ͍͍͕ʜ case class Contract (…) { def
unBilledAvailabilities: Seq[Availability] = availabilities.filter(_.status = UnBilled) // ະٻͷར༻ def nextBillingDate(today: Localdate): LocalDate = unBilledAvailabilities .filter(_.billingDate > today) // ٻ͕ࠓΑΓະདྷͰ .minBy(_.billingDate.toEpochDay) // ٻ͕࠷աڈͷͷ .billingDate }
2020.08.30 19 ٻΛൃੜͤ͞Δ ٻίϯςΩετͰར༻Λ৮ͬͨΓ͢Δ case class Billing(…) object Billing {
def createBilling(today: LocalDate, contract: Contract): Billing = { val availabilities = contract.shouldCreateBilling(today) val billing = ??? // TODO: ར༻ΛͬͯٻΛ࡞Δ } }
2020.08.30 20 ͱ͍͏Θ͚Ͱ
2020.08.30 21 4FRʹϝιουΛੜ͍ͨ͠
!QJDUJOZ 1SF4DBMB.BUTVSJ -JHIUOJOH5BML 4DBMBॳ৺ऀ ̋̋̋ʹϝιουΛ ੜ͍ͨ͠ͱߟ͑ͨ
!QJDUJOZ 1SF4DBMB.BUTVSJ -JHIUOJOH5BML 4DBMBॳ৺ऀ ̋̋̋ʹϝιουΛ ੜ͍ͨ͠ͱߟ͑ͨ Seq
2020.08.30 24 4FRʹϝιουΛੜ͍ͨ͠ ҙຯΛ࣋ͬͨίϨΫγϣϯૢ࡞ʹ໋໊͍ͨ͠ ϩδοΫͷݟ௨͠ΛΑ͍ͨ͘͠ *%&ͷίʔυิΛޮ͔͍ͤͨ
2020.08.30 25 ʮͦΕJNQMJDJUͰͰ͖ΔΑʯ
2020.08.30 26 ☺
2020.08.30 27 ʮ͓͢͢Ί͠ͳ͍͚Ͳʯ
2020.08.30 28
2020.08.30 29 JNQMJDJU 4FRʹϝιουΛੜͤΔ͕ʜ ఆٛ͢Δॴ͕͍͠ υϝΠϯʁ Ͳ͜Ͱఆٛ͞Ε͍ͯΔ͔ ݺͼग़͠ଆ͔Β Θ͔Γʹ͍͘
υϝΠϯࣝJNQMJDJUͨ͘͠ͳ͍
2020.08.30 30 ͡Ό͋Ͳ͏͢Δ͔
2020.08.30 31 υϝΠϯࣝܕʹ͠Α͏
2020.08.30 32 ར༻ͷίϨΫγϣϯΦϒδΣΫτԽ ܖར༻ίϨΫγϣϯΦϒδΣΫτΛ࣋ͭΑ͏ʹͳΔ case class Availabilities( values: Seq[Availability] )
case class Contract ( id: ContractId, availabilities: Availabilities, // ίϨΫγϣϯΦϒδΣΫτΛ࣋ͭ status: ContractStatus, pricing: …, )
2020.08.30 33 ະٻͷར༻ΛٻΊΔ ར༻ͷυϝΠϯࣝͱ࣮ͯ͠Ͱ͖Δ case class Availabilities (…) { def
unBilledAvailabilities: Availabilities = Availabilities(availabilities.filter(_.status = UnBilled)) }
2020.08.30 34 ٻΛൃੜͤ͞Δ ར༻ίϨΫγϣϯܕΛૢ࡞͢ΕΑ͘ͳΔ case class Billing(…) object Billing {
def createBilling(today: LocalDate, contract: Contract): Billing = { val availabilities: Availabilities = contract.shouldCreateBilling(today) // AvailabilitesܕΛฦ͢ val billing = ??? // TODO: ར༻ΛͬͯٻΛ࡞Δ } }
2020.08.30 35 ίϨΫγϣϯΦϒδΣΫτͷར ϝιου͕ੜͤΔ ܕͷදݱྗ͕͑Δ ϦϑΝΫλ͍͢͠ 'JOE6TBHFͰӨڹൣғ͕Θ͔Γ͍͢
2020.08.30 36 5JQT ඪ४తͳૢ࡞USBJUͰܧঝͰ͖ΔΑ͏ʹ͓ͯ͘͠ͱศར trait class CustomCollection[A] { val values:
Seq[A] def isEmpty: Boolean = values.isEmpty def nonEmpty: Boolean = values.nonEmpty def length: Boolean = values.length … }
2020.08.30 37 ؾ͖ 4FRʹϝιουΛੜ͍ͨ͠ͱߟ͑ͨ Ͱɺ4FRʹϝιουΛੜ͢ͷ͋͘·Ͱखஈ ͳͥͦ͏ߟ͑ͨͷ͔ɺཧ༝ΛݴޠԽ͢Δ͜ͱ͕େࣄ ผͷखஈͰత͕ୡͰ͖Δ͜ͱ͋Δ
2020.08.30 38 ·ͱΊ 4FRʹϝιουΛੜͨ͘͠ͳͬͨ ίϨΫγϣϯ͕υϝΠϯϩδοΫΛ࣋ͭ͜ͱ͕͋Δ υϝΠϯϩδοΫΛ࣋ͭͷܕͱͯ͠ఆٛ͢Δͷ͕Α͍ *%&ͷԸܙେ͖͍
2020.08.30 39 4DBMBΤϯδχΞ࠾༻த
2020.08.30 40