Slide 1

Slide 1 text

KOTLINʹΑΔ
 FACTORYϝιου
 ࣮૷ύλʔϯ 2019/11/27 KotlinѪ޷ձLT খࢁ ݈ଠ (Koyama Kenta)
 Twitter/Github @doyaaaaaken

Slide 2

Slide 2 text

ࣗݾ঺հ • ࢓ࣄ • SaaSελʔτΞοϓͰϑϧελοΫΤϯδχΞ(ͱ͍͏໊ͷͳΜͰ΋԰)ͯ͠·͢ • Kotlin͸αʔόαΠυʢJVMʣͰ࢖͍ͬͯ·͢ • झຯ • ອըɾϘʔυήʔϜɾຑ੃ɾςχεɾϙʔΧʔ… • OSSपΓͷ׆ಈ • Kotlin੡OSS΁ͷίϯτϦϏϡʔτ(ktor, Exposed, kotlintest, kohttp) • kotlin-csvͱ͍͏ࣗ࡞OSS࡞ͬͯ·͢ • ktorͷυΩϡϝϯτ೔ຊޠ຋༁ϓϩδΣΫτͷൃىਓͰ͢

Slide 3

Slide 3 text

ձࣾ঺հ smartroundגࣜձࣾͰ
 ىۀՈɾ౤ࢿՈؒͷ
 ࢿۚௐୡϓϩηεΛ؅ཧ͢Δ
 SaaSͷ։ൃΛ͍ͯ͠·͢
 ʢktor͕1.0.0-betaͷࠒʹ։ ൃελʔτ͠·ͨ͠ʣ https://jp.smartround.com/ ٕज़঺հࢿྉ͸ͪ͜Β https://gitpitch.com/smartround/smartround-tech-presentation

Slide 4

Slide 4 text

ࣄͷൃ୺ɻ͜ɺ͜Ε͸…ʁʁ

Slide 5

Slide 5 text

ͳ͔ͳ͔໘നͦ͏͡Όͳ͍͔… 1. ຊͳͷʹBeta Releaseͱ͸೗Կʹʁʁ 2. ༗໊ͳEffective XXXγϦʔζ 3. ෷͏ֹۚΛͳΜͱࣗ෼ͰܾΊΕΔ
 ʢԼݶ͸͋Γ·͢ʣ

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

ࠓճͷൃද಺༰ • શ52ষͷ͏ͪݸਓతʹྑ͔ͬͨͱײͨ͡ষΛൃද • ʰItem33: Consider factory functions instead of constructorsʱ • ҎԼ̎఺ʹ͍ͭͯઆ໌ 1. ͦ΋ͦ΋ͳΜͰίϯετϥΫλΑΓFactoryϝιουͷ΄͏͕
 ྑ͍ͷ͔ʁ 2. KotlinͰFactoryϝιου࣮૷͢Δ৔߹ʹ͸Ͳ͏͍͏ॻ͖ํ͕
 Φεεϝ͔ʁ

Slide 8

Slide 8 text

1. FACTORYϝιουͷ΄͏͕ྑ͍ཧ༝ • ʰFactoryϝιουʹ͢΂͖8ͭͷཧ༝ʱ͕ॻ͔Ε͍ͯͨͷͰʢϑϧ Ϙοίʣ5ͭʹݫબ͠·͢

Slide 9

Slide 9 text

1. FACTORYϝιουͷ΄͏͕ྑ͍ཧ༝ • ͦͷ1.
 ίϯετϥΫλͱҧͬͯɺؔ਺ʢFactoryϝιουʣʹ͸
 ໊લ͕͚ͭΒΕΔ •

Slide 10

Slide 10 text

1. FACTORYϝιουͷ΄͏͕ྑ͍ཧ༝ • ͦͷ2.
 ίϯετϥΫλͱҧͬͯɺؔ਺ʢFactoryϝιουʣ͸
 ฦΓ஋ΛαϒλΠϓʹͰ͖Δ •

Slide 11

Slide 11 text

1. FACTORYϝιουͷ΄͏͕ྑ͍ཧ༝ • ͦͷ3.
 ίϯετϥΫλͱҧͬͯɺؔ਺ʢFactoryϝιουʣ͸
 ඞͣΠϯελϯεΛੜ੒͢Δඞཁ͸ͳ͍ •

Slide 12

Slide 12 text

1. FACTORYϝιουͷ΄͏͕ྑ͍ཧ༝ • ͦͷ4.
 ؔ਺ʢFactoryϝιουʣ͸ՄࢹੑΛॊೈʹ੍ޚͰ͖Δ •

Slide 13

Slide 13 text

1. FACTORYϝιουͷ΄͏͕ྑ͍ཧ༝ • ͦͷ5.
 ίϯετϥΫλͱؔ਺ʢFactoryϝιουʣ͸
 ҟͳΔҾ਺ʹ͢Δ͜ͱ͕Ͱ͖Δ •

Slide 14

Slide 14 text

— EffectiveKotlinΑΓ ͳΜ΍͔Μ΍৭ʑཧ༝͋Δ͔Β
 ͱΓ͋͑ͣΠϯελϯεੜ੒࣌ ʹ͸FACTORYϝιου࢖͓͏ ” “ ͜͜·Ͱͷ·ͱΊ

Slide 15

Slide 15 text

2. FACTORYϝιου࣮૷ɺͲΜͳํ๏͕͋Δʁ • ͳΜͱ5ͭ΋঺հ͞Ε͍ͯ·ͨ͠ 1. Companion object factory function 2. Extension factory function 3. Top-level factory functions 4. Fake constructors 5. Methods on a factory class

Slide 16

Slide 16 text

2. FACTORYϝιου࣮૷ɺͲΜͳํ๏͕͋Δʁ • 1. Companion object factory function
 
 Javaͱࣅ͍ͯΔ͜ͱɺಛʹ՝୊͕ͳ͍͜ͱ͔Β࠷ਪ঑

Slide 17

Slide 17 text

2. FACTORYϝιου࣮૷ɺͲΜͳํ๏͕͋Δʁ • 2. Extension factory function
 
 companion object͕ʢྫ͑͹ϥΠϒϥϦ಺ʹ͋ΔͳͲͯ͠ʣमਖ਼͕ Ճ͑ΒΕͳ͍Α͏ͳͱ͖ʹ༗༻ɻ

Slide 18

Slide 18 text

2. FACTORYϝιου࣮૷ɺͲΜͳํ๏͕͋Δʁ • 3. Top-level factory functions
 
 listOfϝιουͱ͔͸͜ͷύλʔϯɻ
 publicʹͨ͠৔߹ɺIDEͷม׵ީิʹग़ͯ͘Δܽ఺͕͋Δɻ
 privateʹ͢ΔέʔεͰ͸࢖͍উखྑͦ͞͏ɻ

Slide 19

Slide 19 text

2. FACTORYϝιου࣮૷ɺͲΜͳํ๏͕͋Δʁ • 4. Fake constructors
 
 ίϯετϥΫλͬΆ͍ݟͨ໨Ͱݺͼग़ͤΔ͕࣮͸ϝιουͰͨ͆͠
 ͱ͍͏ύλʔϯɻ
 ໋໊ن໿ʹҧ൓͍ͯ͠Δͷ͕ܽ఺ʢϝιουͳͷʹେจࣈ࢝·Γʣ

Slide 20

Slide 20 text

2. FACTORYϝιου࣮૷ɺͲΜͳํ๏͕͋Δʁ • 5. Methods on a factory class
 
 ͍ΘΏΔBuilderύλʔϯɻ
 ͪͳΈʹEffective Kotlinͷ࣍ͷষͰղઆ͞Ε͍ͯΔ͕ɺ
 BuilderύλʔϯΛ࢖͏΂͖έʔε͸গͳ͍ɻ
 ʢ໊લ෇͖Ҿ਺ɾσϑΥϧτҾ਺Λ࢖͑͹େ఍ࣄ଍ΓΔʣ

Slide 21

Slide 21 text

— EffectiveKotlinΑΓ FACTORYϝιουʹ͸
 COMPANION OBJECTΛ ࢖͏ͷ͕͍͍ ” “ ͜͜·Ͱͷ·ͱΊ

Slide 22

Slide 22 text

• ಉ಺༰ͰɺKotlin Advent Calenderʹ౤ߘ༧ఆͷQiitaهࣄ͕͋Δͷ ͰৄࡉؾʹͳΔํ͸ҎԼΛ͝ࢀর͍ͩ͘͞ • https://qiita.com/doyaaaaaken/items/0c99da9efa7d724a0d80

Slide 23

Slide 23 text

HAVE A NICE KOTLIN!