Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DDD + Clean Architecture + UCDOM Full版

DDD + Clean Architecture + UCDOM Full版

http://ddd-cqrs-es.connpass.com/event/27181/
「Reactive Messaging Patternsプレ読書会 - CQRS、ESの基本を学ぶ -」の時間の都合上カットした部分も含めたフル版資料です。
Embeddedなままだと各種リンクが有効ではないので、気になる方は"Download PDF"よりご参照ください。

Essence版はコチラ:https://speakerdeck.com/yoskhdia/ddd-plus-clean-architecture-plus-ucdom-essenceban

Yoshitaka Okuda

March 20, 2016
Tweet

More Decks by Yoshitaka Okuda

Other Decks in Programming

Transcript

  1. DDD + Clean Architecture
    ʴϢʔεέʔεۦಈ։ൃͷྑ͍ͱ͜ΖΛऔΓೖΕΑ͏
    Full൛
    2016/03/16
    @yoskhdia
    DDD+CQRS+EventSourcing࣮૷͢Δձ
    ϋογϡλάɿ#ddd_cqrs_es_tokyo

    View full-size slide

  2. About me
    • ԞాՂڗʢYoshitaka Okudaʣ
    • גࣜձࣾSocketʢKDDI Syn.ϗʔϧσΟϯάεάϧʔϓʣ

    ΞʔΩςΫτ
    • Twitter @yoskhdia
    • interested in DDD/Scala/C#/Reactive System/

    Architect/System Thinking/Team Building/

    Agile/ܦӦ৘ใֶ/On-Road Bike

    View full-size slide

  3. Agenda
    • υϝΠϯۦಈઃܭʢDDDʣ͓͞Β͍
    • Clean Architectureͱ͸Կ͔
    • DDD + Clean Architectureମݧஊ
    • Ϣʔεέʔεۦಈ։ൃʢICONIXϓϩηεʣʹ
    ग़ձͬͨ࿩

    View full-size slide

  4. ཹҙࣄ߲
    • ͜ͷൃද͸ࢲݸਓͷݟղʹدΔ΋ͷͰ͢ɻ
    • ॻ੶ʮυϝΠϯۦಈઃܭʯ΋ਖ਼ࣜʹ͸ʮΤϦοΫɾΤϰΝϯ
    εͷʯͱ෇͘Α͏ʹɺDDD͸ϕετϓϥΫςΟεΛ·ͱΊͨ
    ஌ࣝମܥͰ͋Γɺઈରͷਖ਼ղͷ͋Δ΋ͷͰ͸͋Γ·ͤΜɻ
    • ࠾༻͢ΔϓϩμΫτͷੑ֨ʹΑͬͯɺ۩ମతͳํ๏͸มΘΓ
    ·͢ɻʢࠓճ͸UIΛ࣋ͨͳ͍APIͰߟ͍͑ͯ·͢ɻʣ
    • ͦͷͨΊɺ͜͏͍͏෩ʹద༻͍ͯ͠Δਓ΋͍ΔΜͩͳɺͱ͍
    ͏Թ͔͍৺Ͱ͓ئ͍͍ͨ͠·͢...

    View full-size slide

  5. υϝΠϯۦಈઃܭʢDDDʣ
    ͓͞Β͍
    ίΞυϝΠϯ
    ϢϏΩλεݴޠ
    ϞσϧΛ୳ٻ

    View full-size slide

  6. ͬ͘͟ΓDDD
    • DDD͸ݴ༿Λେ੾ʹ͢Δ։ൃख๏
    • ΤΫετϦʔϜϓϩάϥϛϯάʢXPʣΛϕʔεʹϞσϧۦಈઃܭΞϓ
    ϩʔνΛద༻͍ͯ͠Δ
    • ϏδωεมԽʹͲ͏ରԠ͍͔͕ͯ͘͠ςʔϚ
    • ͦͷͨΊʹదԠܕͷϓϩηεͱϞσϧۦಈઃܭΛ࢖͏
    • ʢݸਓతʹࢥ͏ͷ͸ʣνʔϜͷڌΓॴͱͳΓಘΔ
    • ໎ͬͨΒಡΉ
    • νʔϜͷڞ௨ཧղͷݩʹͳΔˠΦϨ༷։ൃख๏͔Βͷ୤٫

    View full-size slide

  7. ݴ༿ͷఆٛʢݪଇʣ
    • υϝΠϯʢDomainʣ
    • Ϗδωεશମͷ໰୊ྖҬͦͷ΋ͷͷ͜ͱɻιϑτ΢ΣΞͰղܾ͢Δͷ͸ɺ͜ͷҰ෦ɻ
    • υϝΠϯϞσϧʢDomain Modelʣ
    • υϝΠϯʹରͯ͠ɺͦͷղܾࡦʢιϦϡʔγϣϯʣΛϞσϧԽͨ͠΋ͷɻ
    • υϝΠϯΤΩεύʔτʢDomain Expertʣ
    • υϝΠϯʹਫ਼௨͍ͯ͠ΔਓɻҰਓͰ͋Δ͜ͱ΋͋Ε͹ෳ਺ਓͰ͋Δ͜ͱ΋͋Δɻ
    • ίΞυϝΠϯʢCore Domainʣ
    • υϝΠϯ͸͍͔ͭ͘ͷྖҬʹ෼ׂ͢Δ͜ͱ͕ଟ͍ɻ͜ͷ࣌ɺҰ൪ϏδωεՁ஋ͷߴ͍ྖ
    ҬΛίΞυϝΠϯͱ͍͏ɻ࣌ؒ΍ਓ͸༗ݶͳͷͰίΞυϝΠϯΛݟ͚ͭͯɺͦ͜ʹ஫ྗ
    ͢Δ͜ͱ͕ॏཁɻ

    View full-size slide

  8. ݴ༿ͷఆٛʢݪଇʣ
    • ϢϏΩλεݴޠʢUbiquitous Languageʣ
    • ίʔυΛॻ͍͍ͯΔͱΦϨΦϨ໋໊Λ͕ͪ͠ɻ͢ΔͱɺυϝΠϯΤΩεύʔτ
    ͱ࿩Λ͢Δͱ͖ʹݴ༿ͷ຋༁͕ൃੜ͢Δɻ͜͏ͳΔͱɺυϝΠϯΤΩεύʔτ
    ͷඳ͘Ϟσϧͱίʔυ͕ဃ཭͍ͯͬͯ͠͠·͏ͷͰɺυϝΠϯΤΩεύʔτΛ
    ؚΉνʔϜશମͰಉ͡ݴ༿Λ࢖͏Α͏ʹ߹ҙ͢Δɻ
    • ڥք͚ͮΒΕͨίϯςΩετʢBounded Contextʣ
    • จ຺ʢίϯςΩετʣʹΑͬͯɺಉ͡ݴ༿ͳͷʹҟͳΔҙຯʹͳΔ͜ͱ͕͋Δɻ
    υϝΠϯϞσϧ͸େ͖͘ͳΓ͕ͪͳͷͰɺҰ؏ੑΛอͬͨ··εέʔϧ͢Δʹ
    ͸ɺίϯςΩετͷڥքΛϋοΩϦͤͯ͞ҙຯͷมΘΒͳ͍৔ॴΛ࡞Δɻίϯ
    ςΩετϚοϓͱ͍͏πʔϧΛ࢖ͬͨΓ͢Δɻ

    InfoQʮίϯςΩετϚοϐϯάʹΑΔઓུతυϝΠϯۦಈઃܭʯΛࢀর

    View full-size slide

  9. υϝΠϯͱίϯςΩετͷؔ܎
    υϝΠϯ
    ίϯςΩετ
    αϒυϝΠϯ
    ίΞυϝΠϯ
    • ఺ઢɿ

    υϝΠϯڥք
    • ੺࣮ઢɿ

    ίϯςΩετڥք
    • ίϯςΩετ͸͍
    ͔ͭ͘ͷυϝΠϯ
    ڥքʹލΔ͜ͱ͕
    ͋Δ
    • ཧ૝͸αϒυϝΠ
    ϯͱίϯςΩετ
    ͕1ର1 αϒυϝΠϯ

    View full-size slide

  10. ݴ༿ͷఆٛʢ࣮ફʣ
    • ΤϯςΟςΟʢEntityʣ
    • ʢޡղΛڪΕͣʹݴ͑͹ʣҰൠʹ૝૾͢ΔϞσϧͷجຊ୯ҐɻϥΠϑαΠΫϧ
    ͕͋Δɻ
    • ू໿ʢAggregateʣ
    • ͍͔ͭ͘ͷΤϯςΟςΟؒͰ੔߹ੑΛอͨͳ͚Ε͹Ϟσϧͱͯ͠੒ཱ͠ͳ͍৔
    ߹ʢྫ͑͹ɺ஫จͱ஫จ໌ࡉʣ͕͋Δɻ͜ΕΒͷΤϯςΟςΟΛଋͶͨͱ͖ɺ
    ͦͷϧʔτʹҐஔ͢ΔΤϯςΟςΟΛू໿ͱݺͿɻ
    • ஋ΦϒδΣΫτʢValue Objectʣ
    • ϥΠϑαΠΫϧ͸ແ͘ෆมͷΦϒδΣΫτɻϢϏΩλεݴޠͰఆٛ͞Εͨݴ༿
    ͱৼΔ෣͍Λ࣋ͭ͜ͱͰυϝΠϯϞσϧ͕๛͔ʹͳΔɻ

    View full-size slide

  11. ݴ༿ͷఆٛʢ࣮ફʣ
    • υϝΠϯαʔϏεʢDomain Serviceʣ
    • ෳ਺ͷΤϯςΟςΟʹ·͕ͨΔৼΔ෣͍ͳͲɺΤϯςΟςΟ͕࣋ͭʹ͸ద͞
    ͳ͍ৼΔ෣͍Λఆٛͨ͠υϝΠϯΦϒδΣΫτɻঢ়ଶΛ࣋ͬͯ͸͍͚ͳ͍ɻ
    • ϑΝΫτϦʢFactoryʣ
    • ෳࡶͳΦϒδΣΫτ΍AggregateΛੜ੒͢ΔͨΊͷ࣮૷ύλʔϯɻΤϯςΟ
    ςΟͷϥΠϑαΠΫϧͷى఺ʹͳΔɻ
    • ϦϙδτϦʢRepositoryʣ
    • ΤϯςΟςΟͷϥΠϑαΠΫϧʹ్͓͍ͯதʢঢ়ଶͷ෮ݩʣͱ࠷ޙʢ࡟আʣ
    Λ୲͏࣮૷ύλʔϯɻAggregateʹରͯ͠ͷΈ༻ҙ͢Δɻ

    View full-size slide

  12. ଓ͖͸ࢀߟࢿྉͰ

    View full-size slide

  13. DDDΛ΍Δҙٛ
    • υϝΠϯϞσϧ͕ચ࿅͞Ε͍ͯ͘͜ͱͰɺ
    • ʮۀ຿஌ࣝʯ-ʮݴ༿ʯ-ʮίʔυʯ͕࿈ಈ
    • ֎͔ΒͷมԽʹదԠ͠΍͘͢
    • ։ൃΛਐΊΔ͜ͱʹΑͬͯൃݟ͞ΕΔ৽ͨͳ
    ஌ݟΛϏδωε΁ؐݩ

    View full-size slide

  14. –Jim HighsmithࢯʮWhat is Agility?ʯ
    “ΞδϟΠϧ͞ͱ͸ɺܹม͢ΔϏδωε؀
    ڥʹ͓͍ͯརӹΛੜΈग़ͨ͢ΊʹɺมԽ
    ʹରԠ͢Δͱಉ࣌ʹɺมԽΛ࡞Γग़͢ೳ
    ྗͰ͋Δɻ”

    View full-size slide

  15. ͦΕΛ࣮ફ͢ΔͨΊͷDDD
    υϝΠϯϞσϦϯάΛ௨ͯ͡
    ։ൃऀ͕Ϗδωεʹد༩͢Δ

    View full-size slide

  16. Clean Architectureͱ͸Կ͔
    γεςϜʹߏ଄Λ༩͑
    ґଘؔ܎نଇΛఆٛ͢Δ

    View full-size slide

  17. ଞͷΞʔΩςΫνϟ
    -BZFSFE"SDIJUFDUVSF
    ૚Ͱ෼཭
    Πϯϑϥʹґଘ
    )FYBHPOBM"SDIJUFDUVSF
    ΠϯϑϥΛ֎෦Խ
    "EBQUFSͰܨ͙
    0OJPO"SDIJUFDUVSF
    "QQMJDBUJPO
    Λ૚Խ

    View full-size slide

  18. ଞͷΞʔΩςΫνϟ
    • ϨΠϠʔυΞʔΩςΫνϟ
    • UI૚ˠΞϓϦέʔγϣϯ૚ˠυϝΠ
    ϯ૚
    • Πϯϑϥ૚͸શͯʹґଘ͞ΕΔ
    • DDDຊͰ΋ݴٴ
    • IDDDຊͰ͸ΠϯϑϥΛ࠷্Ґʹ൓స

    ˠΠϯϑϥͷ֎෦ԽΛਐΊΔͱɺ࣍
    ߲Ҏ߱ͷΞʔΩςΫνϟʹͭͳ͕Δ

    View full-size slide

  19. ଞͷΞʔΩςΫνϟ
    • ϔΩαΰφϧΞʔΩςΫνϟ
    • Ports & AdaptersΞʔΩςΫνϟ
    ͱ΋ݴ͏
    • த৺ʹApplicationΛஔ͖ɺΠϯϑ
    ϥʢUIɺDBɺetcʣΛ֎ଆʹஔ
    ͘ɻ྆ऀʹ͸Portͱݺ͹ΕΔޱ͕
    ͋ΓɺAdapterʹΑͬͯ઀ଓ͞Ε
    Δɻ
    • IDDDຊͰ΋ݴٴ

    View full-size slide

  20. ଞͷΞʔΩςΫνϟ
    • ΦχΦϯΞʔΩςΫνϟ
    • ϔΩαΰφϧͱಉ͡ͰΠϯϑϥ
    Λ֎෦Խ͍ͯ͠Δ
    • ϔΩαΰφϧͱͷҧ͍
    • ApplicationΛ૚Խ
    • ૚ͷґଘํ޲͸಺ଆ΁޲͔͏
    • ७ਮʹϨΠϠʔυͷΠϯϑϥ
    ૚Λ֎ʹ͖࣋ͬͯͨײ͡

    View full-size slide

  21. ͍ͣΕ΋
    ιϑτ΢ΣΞΛ෼ׂ͠
    ߏ଄Λ໌֬ʹ͢Δ
    ͭ·Γɺؔ৺ࣄͷ෼཭

    View full-size slide

  22. Clean Architecture
    ΋ͦͷҰ೿

    View full-size slide

  23. CMPHUIMJHIUDPNVODMFCPCUIF
    DMFBOBSDIJUFDUVSFIUNM

    View full-size slide

  24. Clean Architecture֓ཁ
    • ԁঢ়ͷ૚͸ɺιϑτ΢ΣΞͷҟͳΔྖҬΛද͢
    • த৺ʹ͍͘΄ͲɺϏδωεՁ஋ͷߴ͍΋ͷΛஔ͘
    • ֎ଆͷԁ͸ϝΧχζϜɻ಺ଆͷԁ͸ϙϦγʔɻ
    • ґଘؔ܎نଇ͕؊
    • ૚͸ࣗ෼ΑΓ಺ଆͷ૚͚ͩʹґଘ͢Δ͜ͱ

    ˠ ֎ଆͷ૚ʹ͍ͭͯ͸શ͘Կ΋஌Βͳͯ͘ྑ͍
    • σʔλܗࣜ΋ಉ༷ʹ֎ଆͷ૚ͷϑΥʔϚοτΛ಺ଆʹ࣋ͪࠐ·ͳ͍ʢྫ͑͹ɺ
    JSONΛ࣋ͪࠐ·ͳ͍ɺDBͷRowΦϒδΣΫτΛ࣋ͪࠐ·ͳ͍ʣ
    • ಺ଆͷಠཱੑʢந৅౓ʣΛߴΊͯɺ֎ଆͷަ׵Λ༰қʹ͢Δ

    View full-size slide

  25. Hexagonal΍Onionͱૂ͍͸ಉ͡
    • ϑϨʔϜϫʔΫ͔Βಠཱ͢Δ

    ㅟ ㅟ ㅟ ㅟ
    ΞʔΩςΫνϟ͸ϥΠϒϥϦͷଘࡏʹґଘ͠ͳ͍ɻϑϨʔϜϫʔΫͱ͍͏੍໿ʹγεςϜΛ
    ٧ΊࠐΉͷͰ͸ͳ͘ɺγεςϜʹϑϨʔϜϫʔΫΛ౰ͯ͸ΊΔɻ
    • UI͔Βಠཱ͢Δ

    ㅟ ㅟ ㅟ ㅟ
    UI͸ɺγεςϜͷ࢒Γͷ෦෼Λมߋ͢Δ͜ͱͳ͘ɺ༰қʹมߋ͢Δ͜ͱ͕Ͱ͖Δɻྫ͑͹
    Web UI͔ΒίϯιʔϧUI΁ͱஔ͖׵͑Δ͜ͱ͕Ͱ͖Δɻ
    • σʔλϕʔε͔Βಠཱ͢Δ

    ㅟ ㅟ ㅟ ㅟ
    Oracle·ͨ͸SQL ServerɺMongo΍BigTableͱ͍ͬͨNoSQLؚΊɺަ׵Λ༰қʹ͢Δɻ
    Ϗδωεϧʔϧ͸ɺσʔλϕʔεʹؚΊͳ͍ɻ
    • ೚ҙͷ֎෦ϦιʔεɺαʔϏε͔Βಠཱ͢Δ

    ㅟ ㅟ ㅟ ㅟ
    Ϗδωεϧʔϧ͸ɺ୯७ʹ֎ͷੈքʹ͍ͭͯ͸Կ΋஌Δඞཁ͸ͳ͘ɺ΍Γ͍ͨ͜ͱ͚ͩʹ
    ूத͢Ε͹ྑ͍ɻ

    View full-size slide

  26. Clean Architectureͷར఺͸ʁ
    • ϔΩαΰφϧʴΦχΦϯɺͦΕͧΕͷ͍͍ͱ͜औΓ͕Clean Architecture
    • ΞϓϦέʔγϣϯʹ૚Λ༩͑ΠϯϑϥͱΞμϓλͰܨ͙
    • ґଘؔ܎نଇ͕໌ࣔ͞Ε͍ͯΔ͜ͱ
    • ୯७ʹਤΛݟͯ෼͔Γ΍͍͢
    • Adapter૚͕઀ଓΛ୲ͬͯɺ֎ͱܨ͕ΕΔͷ͸UseCaseʹݶఆ
    • ૚ͷڥքҧ൓͸DIPͰ๷ࢭ
    • ໨ࢦͯ͠Δ΋ͷ͸ͲΕ΋ಉ͡ͳͷͰɺνʔϜͰཧղΛಘΒΕ΍͍͢΋ͷΛ
    ࢖͑͹OK

    View full-size slide

  27. The Clean Architecture
    ͷఆٛ

    View full-size slide

  28. %PNBJO૚
    اۀશମͷϏδωεϧʔϧ
    ΛΧϓηϧԽ
    6TF$BTF૚
    ΞϓϦέʔγϣϯͷ
    ϏδωεϧʔϧΛΧϓηϧԽ
    "EBQUFS૚
    ಺ͱ֎ͷσʔλͷม׵͕ओ
    'SBNFXPSL%SJWFS૚
    ۩ମతͳπʔϧ

    View full-size slide

  29. Entities(=Domain)
    • ϨΠϠʔυΞʔΩςΫνϟͰ͍͏υϝΠϯ૚
    • اۀશମͷϏδωεϧʔϧΛΧϓηϧԽ
    • ϝιουΛ࣋ͭΦϒδΣΫτɺ͋Δ͍͸ɺσʔλߏ଄ͱػೳͷηοτ
    • DDDຊʹ༷ʑͳύλʔϯऩ࿥
    • اۀ಺ͷ༷ʑͳΞϓϦέʔγϣϯʹΑͬͯ௕͘࢖ΘΕΔ
    • ಛఆͷΞϓϦέʔγϣϯͷӡ༻ͷมߋʢྫ͑͹ɺϖʔδφϏήʔγϣϯ΍η
    ΩϡϦςΟʣͷӨڹΛΤϯςΟςΟʹ༩͑Δ΂͖Ͱ͸ͳ͍
    • اۀΛލ͕ͳ͍୯ҰͷΞϓϦέʔγϣϯΛॻ͍͍ͯΔ৔߹ͩͱɺΤϯςΟ
    ςΟ͸ΞϓϦέʔγϣϯͱີ઀ʹ݁͹Ε͕ͪɻ

    View full-size slide

  30. Use Cases
    • ϨΠϠʔυΞʔΩςΫνϟͰ͍͏ΞϓϦέʔγϣϯʢαʔϏεʣ૚
    • ΞϓϦέʔγϣϯݻ༗ͷϏδωεϧʔϧΛΧϓηϧԽ
    • γεςϜͷϢʔεέʔεΛ࣮૷͢ΔɻυϝΠϯ΁ͷσʔλͷྲྀΕ
    Λௐ੔͠ɺ·ͨɺυϝΠϯΦϒδΣΫτ΁ࢦࣔΛग़͢ɻ
    • ͜ͷ૚ͷมߋ͕υϝΠϯ૚ʹӨڹͨ͠ΓɺDB΍UIͷΑ͏ͳ֎෦
    ͷมߋʹΑͬͯӨڹΛड͚ͳ͍Α͏ʹ͢Δ͜ͱ͕େࣄɻ
    • ͔͠͠ɺΞϓϦέʔγϣϯૢ࡞ʹมߋ͕͋Δ৔߹ɺ͜ͷ૚͸Өڹ
    Λड͚ΔɻϢʔεέʔεͷৄࡉΛมߋ͢ΔͳΒɺ͜ͷ૚ͷҰ෦ͷ
    ίʔυ͸࣮֬ʹӨڹΛड͚Δ͜ͱʹͳΔɻ

    View full-size slide

  31. Interface Adapters
    (Controllers/Presenters/Gateways)
    • ϑϨʔϜϫʔΫͳͲΛ࢖͍ɺ۩ମతͳϝΧχζϜΛ࣮૷͢Δ૚
    • ಺ͱ֎ͱͷσʔλʢϑΥʔϚοτʣͷม׵͕ओͳ໾ׂ
    • Controllerɿ ֎૚͔Βड͚औͬͨσʔλΛ಺૚ͰղऍͰ͖ΔσʔλʢυϝΠϯ
    ΦϒδΣΫτʣʹม׵͢Δɻྫ͑͹ɺϑΥʔϜϦΫΤετΛυϝΠϯΦϒδΣ
    Ϋτʹม׵
    • Presenterɿ ಺૚͔Β఻͑ΒΕͨσʔλΛ֎૚Ͱ࢖༻͢Δܗʹม׵͢Δɻྫ͑
    ͹ɺυϝΠϯΦϒδΣΫτΛJSONʹม׵
    • GatewayʢDB΍֎෦αʔϏεʣɿ ಺૚ʹ͸۩ମతͳ΍ΓऔΓʹؔ͢Δίʔυ͸
    ஔ͔ͳ͍Α͏ʹ͢Δɻྫ͑͹ɺRDBΛ࢖͏࣌ɺSQLͷఆٛ͸͜ͷ૚ʹݶఆ͢Δ

    View full-size slide

  32. Frameworks & Drivers
    (Web/UI/DB/ExternalInterfaces)
    • ࠷΋֎ଆͷ૚͸ɺσʔλϕʔε΍WebϑϨʔϜϫʔΫͳͲ
    ͷπʔϧͰߏ੒͞ΕΔɻ
    • ͜ͷ૚ʹ઀͢Δ಺ଆͷ૚΁ͭͳ͛ΔͨΊͷάϧʔίʔυ
    Ҏ্ͷ΋ͷ͸ॻ͔ͳ͍ɻ
    • Web΍UIɺσʔλϕʔεͷΑ͏ͳ۩ମతͳ࣮૷ٕज़ʹ͸ɺ
    গͳ͔Βͣ֐͕͋Δɻ
    • มԽ͕ܹ͍͠෦෼Ͱ΋͋ΔͷͰɺ࠷΋֎ଆʹஔ͍ͯަ׵
    Λ༰қʹ͓ͯ͘͜͠ͱ͕υϝΠϯΛकΔ͜ͱʹܨ͕Δɻ

    View full-size slide

  33. ઃܭͷϙΠϯτɿڥքͷԣஅ
    • ԁͷํʹ໨͕ߦ͖͕͚ͪͩΕͲɺઃܭͷ͏
    ͑Ͱ͸͕ͬͪ͜ॏཁ
    • ௨ৗɺController͔Βೖ͖ͬͯͯPresenter
    ʹग़ͯߦ͘ྲྀΕ
    • UseCase͸֎૚Λ஌Βͳ͍ͷͰɺग़ྗΛฦ
    ͢ʹ͸ґଘؔ܎ٯసͷݪଇΛ࢖͍ͬͯΔ

    ʢDependency Inversion Principleʣ
    • ૚ͷڥքΛอͪͳ͕ΒॲཧϑϩʔΛ࣮ݱ
    ৄࡉ͸ޙ΄Ͳ

    View full-size slide

  34. ઃܭͷϙΠϯτɿ૚ͷ਺
    • 4ͭͷ૚Ͱද͞Ε͍ͯΔ͚ΕͲɺඞͣ͜͏͠ͳ
    ͚Ε͹͍͚ͳ͍Θ͚Ͱ͸ͳ͍ɻ
    • ॏཁͳͷ͸ɺ
    • ؔ৺ࣄͷ෼཭
    • ґଘؔ܎نଇʢ಺૚ͷΈʹґଘ͢Δʣ

    View full-size slide

  35. ·ͱΊ
    • ඇৗʹγϯϓϧͳϧʔϧͳͷͰ෼͔Γ΍͍͢
    • ૚Ͱ෼཭
    • େ੾ͳ΋ͷΛ಺ଆʹஔ͘
    • ґଘؔ܎نଇʢ಺ଆʹͷΈґଘʣΛकΔ
    • ಠཱੑ͸ςετͷ༰қੑʹ΋ߩݙ͢Δ
    • ٕज़͕ݹ͘ͳͬͨΒ࠷খݶͷखؒͰަ׵Ͱ͖Δ
    • ϑϨʔϜϫʔΫΛަ׵͢Δ͜ͱ͸͋ͬͯ΋ɺυϝΠϯ஌ࣝΛަ׵
    ͢Δͱ͍͏ͷ͸͋Γಘͳ͍

    View full-size slide

  36. DDD + Clean Architecture
    ମݧஊ
    Clean Architecture͸෼͔Γ΍͍͢
    DDDͷ࣮ફ͸νʔϜͰόϥϯεΛߟ͑Δ

    View full-size slide

  37. ࣮૷αϯϓϧ

    github.com/yoskhdia/
    cleanArchSample
    ※Scala + Play! Framework 2.4

    View full-size slide

  38. ύοέʔδߏ੒
    • Domain(Entities)૚
    • Contract૚
    • Domain૚ͱͷڮ౉͠

    ʢDIΛ࢖͏ͷͰΠϯλϑΣʔε͸ผʹ͍ͯ͠Δʣ
    • UseCase૚
    • Adapter૚
    • Repositoryͷ࣮૷Ϋϥε΋͜͜
    • ʢExternal૚ʣ
    • ϑϨʔϜϫʔΫ΍ϥΠϒϥϦͷ૚ͱ͍͏Ґஔ͚ͮ
    ̐૚Ͱͳͯ͘΋0,

    View full-size slide

  39. Domain(Entities)૚
    • POSO(Plain Old Scala Object)͕جຊ
    • ϑϨʔϜϫʔΫ΁ͷґଘ͚ͩͰͳ͘ɺϥΠϒ
    ϥϦ΁ͷґଘ΋ۃྗগͳ͘
    • ࠓͷͱ͜ΖJoda-TimeͷΈʢJava8 Date
    and Time API΁ͷҠߦ͸ݕ౼தʣ

    View full-size slide

  40. Contract/UseCase૚
    *OQVU1PSUͷ࣮૷͸
    6TF$BTF͕ߦ͏
    ґଘؔ܎ٯసͷݪଇͰ6TF$BTF
    ͸0VUQVU1PSUʹग़ྗΛ౉͚ͩ͢
    ʹ૚͕ด͡ΒΕΔ
    0VUQVU1PSUͷ࣮૷͸
    1SFTFOUFS͕ߦ͏
    6TF$BTFͱ෼཭͍ͯ͠ΔͷͰɺ
    1VTIܕ΍1VMMܕͳͲ޷͖ʹ૊
    Έସ͑ΒΕΔ

    View full-size slide

  41. Use Case
    import scala.concurrent.{ExecutionContext, Future}


    trait UseCase {

    type In


    type Out


    protected def call(arg: In)(implicit ec: ExecutionContext): Future[Out]

    }
    "EBQUFS૚ͱͷ࿈ܞ͸1PSUʹҕৡ

    View full-size slide

  42. Input PortʢPushܕʣ
    import scala.concurrent.ExecutionContext

    import scala.util.{Failure, Success}

    trait PushPort[Arg, Result] {

    self: UseCase =>


    override final type In = Arg


    override final type Out = Result


    def execute[T <: Callback[Result]](arg: Arg)(callback: T)

    (implicit ec: ExecutionContext): Unit = {

    call(arg).onComplete {

    case Success(result) =>

    callback.onSuccess(result)

    case Failure(t) =>

    callback.onFailure(t)

    }

    }

    }
    "EBQUFS૚͔ΒͲ͏໯͏͔
    ԿΛฦ͔͢Λఆٛ
    *OQVU1PSUͷ໾ׂ͸
    ड͚औΔ͜ͱ·ͰͳͷͰ
    6OJUΛฦ͢

    View full-size slide

  43. Pullܕ͸࢖͏͜ͱগͳ͍ͷͰׂѪ
    αϯϓϧίʔυ͸ͪ͜ΒͰ͢
    /app/contract/PullPort.scala

    View full-size slide

  44. Output Port
    trait Callback[Result] {


    def onSuccess(result: Result): Unit


    def onFailure(t: Throwable): Unit

    }
    ΞϓϦέʔγϣϯϩδοΫͷΤϥʔ΋
    ಛผͳ&YDFQUJPOΛ༻ҙͯ͠ฦ͢Α͏ʹ͍ͯ͠Δ
    ʢ+BWBͷ׳शʹ͍ۙʣ

    View full-size slide

  45. Callback vs Promise(Future)
    • Scalaʹ͸Promise(Future)͕͋Δ
    • ࢀߟɿhttps://gist.github.com/okapies/5354929

    ※هࣄʹର͢Δίϝϯτ(Togetter)·ͰಡΈ·͠ΐ͏
    • ௿ϨϕϧͳCallbackͷํ͕ಋೖোน͕௿͍
    • ߴϨϕϧͳPromiseΛ࢖͍͍ͨͳΒɺCallbackͷ্
    ʹඃͤΔܗͰ࣮૷͢Δ͜ͱ͕Ͱ͖Δ

    View full-size slide

  46. Callbackͷ্ʹ
    PromiseΛࡌͤΔ
    private class CallbackImpl extends PickedLeaderCallback {

    val promise = Promise[UserId]()

    override def onSuccess(userId: UserId): Unit = {

    promise.success(userId)

    }


    override def onFailure(throwable: Throwable): Unit = {

    promise.failure(throwable)

    }

    }

    View full-size slide

  47. Clean ArchitectureΛ
    ద༻͢ΔͨΊͷิॿ͸͜Ε͚ͩ

    View full-size slide

  48. Use Caseͷఆٛ
    package contract.usecase


    import contract.{PushPort, UseCase}

    import domain.{GroupId, UserId}


    trait PickLeaderUseCase extends UseCase with PushPort[GroupId, UserId]
    ࣮͸αϘ͍ͬͯΔ
    6TF$BTF૚Ͱѻ͍΍͍͢
    ΦϒδΣΫτ %50
    ʹ͢Δ

    View full-size slide

  49. Use Caseͷ࣮૷
    package usecase


    import javax.inject.Inject

    import contract.usecase.PickLeaderUseCase

    import domain.UserRepository


    import scala.concurrent.{ExecutionContext, Future}


    class PickLeaderUseCaseImpl @Inject()(userRepository: UserRepository)
    extends PickLeaderUseCase {


    override protected def call(groupId: In)
    (implicit ec: ExecutionContext): Future[Out] = {

    userRepository.findBy(groupId).map { board =>

    board.pickLeader // ୭ΛͲ͏Ϧʔμʹ͢Δ͔͸υϝΠϯ஌ࣝ

    }

    }

    }
    ΠϯλϑΣʔεΛ࢖͏
    %*ͰґଘΛ୯ํ޲ʹ

    View full-size slide

  50. Adapter૚
    3FQPTJUPSZͷ࣮૷Ϋϥε΋
    ͜ͷ૚ͷத
    42-ఆٛͳͲ
    ֎͔ΒͷೖྗΛ
    ಺ଆͷΦϒδΣΫτʹม׵
    ྫɿ1045͞Εͨσʔλ
    ಺͔Βͷग़ྗΛ
    ֎ଆͷσʔλʹม׵
    ྫɿ+40/

    View full-size slide

  51. Controller
    import contract.usecase.PickLeaderUseCase

    import domain.GroupId

    import play.api.data._

    import play.api.libs.concurrent.Execution.Implicits.defaultContext

    import play.api.mvc.{Action, Controller}


    class GroupController @Inject()
    (useCase: PickLeaderUseCase, presenter: PickedLeaderPresenter)
    extends Controller {

    val form: Form[GroupId] = ??? // ׂѪ

    def pickLeader = Action.async { implicit request =>

    form.bindFromRequest.fold(_ => Future.successful(BadRequest("…")),
    (groupId: GroupId) =>

    presenter.response(useCase.execute(groupId))

    )

    }

    }
    ೖྗσʔλ͔Βͷม׵͕੹຿
    ͜ͷॻ͖ํʹ͍ͭͯ͸ޙ΄Ͳ

    View full-size slide

  52. Presenter
    import contract.callback.PickedLeaderCallback

    import domain.UserId

    import play.api.libs.json.Json

    import scala.concurrent.{ExecutionContext, Future, Promise}


    class PickedLeaderPresenter extends Presenter[PickedLeaderCallback] {


    implicit val writer = Json.writes[UserId]


    override def response(call: UseCaseExecutor)
    (implicit ec: ExecutionContext): Future[Rendered] = {

    val callback = new CallbackImpl

    call(callback)

    callback.promise.future.map { userId =>

    Ok(Json.toJson(userId))

    }

    }

    } ग़ྗσʔλ΁ͷม׵͕੹຿

    View full-size slide

  53. ControllerͰPresenterͷ໾ׂΛ
    ݉೚ͯ͠΋ྑ͍ͷͰ͸ʁ
    • ࠓճͷΑ͏ͳখن໛ͳ΋ͷͩͱɺͻͱͭͷΫϥεʹશ෦ॻ
    ͍ͯ͠·͍ͨ͘ͳΔ
    • ໾ׂͷҟͳΔ΋ͷΛҰͭͷΫϥεʹೖΕΔͷ͸୯Ұ੹೚
    ͷݪଇʹ൓͢Δ
    • Controller͸ೖྗͷม׵ɺPresenter͸ग़ྗͷม׵ʹઐ೦
    ͢Δ͜ͱͰංେԽ͕๷͛Δʢίʔυ͸੒௕͢Δʣ
    • ҰํͰίϯτϩʔϥΛ෼ׂ͢Δٕज़΋࿩୊ʹ

    ઃܭʹ͓͍ͯԿΛੋͱ͢Δ͔ɺ͚ͩ

    View full-size slide

  54. PresenterΛUseCaseʹ
    ౉ͯ͠΋ྑ͍ͷͰ͸ʁ
    • UseCase͔Β௚઀݁ՌΛฦ͢͜ͱʹͳΔ
    • UseCase૚ҎԼʹPresenterͷΠϯλϑΣʔεʢ΋͘͠͸Ϩεϙϯ
    εͷܕʣ͕ඞཁʹͳͬͯ͠·͏ɻͦΕ͸ɺUseCase૚͕֎ଆͷ૚
    ͷ໾ׂ΋݉೚͍ͯ͠Δ͜ͱʹͳͬͯ͠·͏ͷͰ޷·͘͠ͳ͍
    • ୯Ұ੹೚ͷݪଇ͸΋ͱΑΓɺ૚ͱܾͯ͠ΊΒΕͨ໾ׂʹઐ೦ͯ͠૚
    ΛแΜͰ͍͘͜ͱͰɺ಺ଆͷಠཱੑ্͕͕Δ

    ʹ֎ଆͷަ׵༰қੑ্͕͕Δ
    OK: presenter.response(useCase.execute(groupId))

    NG: useCase.execute(groupId)(presenter.response)


    View full-size slide

  55. ͦͷଞ
    • GuiceͷΑ͏ͳDIίϯςφΛ࢖͏ͷ͔ɺScalaͷݴޠػೳΛ
    ࢖ͬͯίϯύΠϧ࣌DIΛ͢Δͷ͔͸ࣗ༝
    • DIίϯςφ͸࣮੷͕͋ΔͷͰɺແཧͯ͠ίϯύΠϧ࣌DI
    ʹ͢Δඞཁ͸ແ͍ͱࢥ͍·͢ɻྫ͑͹ɺScalaΑΓ΋Java
    ͷํ͕෼͔Δϝϯόʔ͕ଟ͍ͳΒૉ௚ʹDIίϯςφ࢖͍
    ·͠ΐ͏ɻ
    • ࠓճ͸ύοέʔδͰ૚Λ෼཭͍ͯ͠·͕͢ɺϚϧνϓϩδΣ
    ΫτͰ෼཭͢Δͱ૚ͷґଘΛڧ੍Ͱ͖ΔͷͰΑΓ޷·͍͠

    View full-size slide

  56. ϓϩμΫτͰͷऔΓ૊Έ

    View full-size slide

  57. ୊ࡐ֓ཁ
    • ϑϩϯτͱAjaxͰ΍ΓऔΓ͢ΔAPIαʔϏε
    • ݱߦͰ͸RailsͰ࡞ΒΕ͍ͯͯɺࠓճ͸ϦϓϨʔε
    • ࢓༷͸ݱߦ౿ऻ
    • Ϟσϧ͸ActiveRecord͔Β୤٫
    • Scala + Play! Framework
    • ߴෛՙ
    • ग़དྷΔݶΓ1౓ͷϦΫΤετʹ͓͞Ί͍ͨ
    • σʔλετΞͳͲ֎෦Ϧιʔε΁ͷΞΫηε͕ूத
    @@'MJQEFTL@@

    View full-size slide

  58. ՝୊
    • ActiveRecordΛ࢖͍ͬͯͨ͜ͱͰɺϞσϧͱσʔλΞΫηε͕
    ີʹͳ͍ͬͯͨ

    ˠͲͪΒͷ౎߹ʹ΋ҾͬுΒΕΔ
    • ϑΝοτϞσϧ΋ࢄݟ͞Εͨ

    ˠ੹຿͕ଟ͍ͱվम೉౓͕ߴ͍
    • νϦ΋ੵ΋Ε͹Ͱɺߴෛՙʹͳͬͨͱ͖ʹશମ͕εϩʔμ΢ϯ

    ˠͲ͜ͰσʔλΞΫηε͍ͯ͠Δͷ͔௥͏ͷ͕େมͳͷͰख͕
    ଧͪʹ͍͘

    View full-size slide

  59. ՝୊ͷଟ͘͸
    σʔλΞΫηεʹू໿͞ΕΔ

    View full-size slide

  60. DDD + Clean ArchitectureͰ
    σʔλΞΫηεΛίϯτϩʔϧ༰қʹ
    • DDDʹै͏ͱRepositoryΛ࢖͏ݸॴ͸ΞϓϦέʔγϣ
    ϯαʔϏεʢUseCaseʣ͔υϝΠϯαʔϏεʹݶఆ͞
    Ε͍ͯ͘
    • ू໿(Aggregate)͕ϥΠϑαΠΫϧ·Ͱ୲͏ͱ੹຿
    ͕େ͖͘ͳΓ͗͢ΔʢIDDD p.254ʣ
    • ࣗવͱσʔλΞΫηεݸॴ͕෼͔Γ΍͘͢
    ※υϝΠϯαʔϏεɿෳ਺ͷΤϯςΟςΟʹ·͕ͨΔৼΔ෣͍ͳͲɺΤϯςΟςΟ͕
    ࣋ͭʹ͸ద͞ͳ͍ৼΔ෣͍Λఆٛͨ͠υϝΠϯΦϒδΣΫτ

    View full-size slide

  61. DDD + Clean ArchitectureͰ
    σʔλΞΫηεΛίϯτϩʔϧ༰қʹ
    • ࠓͷͱ͜ΖυϝΠϯαʔϏεͰRepositoryΛ࢖͍͍ͨέʔε͸ग़͍ͯ
    ͳ͍ͷͰɺUseCaseͰͷΈRepositoryΛ࢖͑ΔΑ͏ʹͯ͠ࢼ͍ͯ͠Δ
    • ҙਤͤͣԿ౓΋ݺͼग़ͯ͠͠·͏Մೳੑ͕͋Δˍ࢖͑Δঢ়ଶͩͱ࢖
    ͍ͨ͘ͳΔͷ͕ਓ৘ͳͷͰActiveRecordͷೋͷ෣͍ʹͳΒͳ͍Α͏
    ஫ҙΛ෷͍ͬͯΔ
    • ґଘؔ܎نଇʹΑͬͯ૚͕ด͡ΒΕ͍ͯΔͷͰɺͲ͜ͰσʔλΞΫ
    ηε͍ͯ͠Δ͔෼͔Γ΍͘͢ͳͬͨ
    • σʔλετΞ͕Ұ൪֎ͳͷͰަ׵͕͠΍͘͢ͳͬͨɻElasticsearch
    ൛ͱDynamo൛ͰύϑΥʔϚϯεൺֱ͔ͯ͠Β࠾༻ΛܾΊΔ౳Մೳ

    View full-size slide

  62. ิ଍ɿRepository I/F
    • αϯϓϧͰ͸Ԡ༻ൣғ޿ΊʹDomain૚ʹஔ͍͍ͯ·͢
    ͕ɺϓϩμΫτͰ͸Contract૚ʹஔ͍͍ͯ·͢
    • PortʹRepositoryͱଊ͑ͯUseCase૚ͰͷΈΞΫηεΛ
    ڐՄʢI/FΛஔ͖ʣ͠ɺͦͷPort(Repository)ͷ࣮૷ʢܧ
    ঝʣ͕Adapter૚Ͱ͞Ε͍ͯΔɺͱ͍͏ղऍ
    • RepositoryΛͲ͏͢Δ͔͸"ઃܭͷ՝୊"

    υϝΠϯϞσϧΛߟ͑Δ͏͑Ͱ͸ຊ࣭Ͱ͸ͳ͍

    View full-size slide

  63. ೉͍͠఺
    • υϝΠϯΦϒδΣΫτΛUseCaseͰ༻ҙͯ͠ࢦࣔΛग़͢
    ඞཁ͕͋ΔͷͰɺจ຺ͱͯࣗ͠વͳͷ͔ɺೲಘͰ͖Δ͔
    Λ܁Γฦ͠ߟ͑Δඞཁ͕͋Δɻ
    • υϝΠϯαʔϏεࣗମ͕ͦ΋ͦ΋ۃྗ࢖Θͳ͍ํ͕ྑ
    ͍΋ͷͰ͸͋Δ͚ΕͲɺෳ਺ͷΤϯςΟςΟʹؔ܎͢
    ΔΑ͏ͳৼΔ෣͍͸υϝΠϯαʔϏεͷํ͕ࣗવɻ
    • ៉ྷͳDDDͱγϏΞͳύϑΥʔϚϯεཁ݅ͷόϥϯεΛ
    ৗʹߟ͑Δ

    View full-size slide

  64. τϥϯβΫγϣϯʹ͍ͭͯ
    • "ू໿ʢAggregateʣ͸τϥϯβΫγϣϯ੔߹ੑͷڥքͱಉٛ"
    ʢIDDD p.340ʣͳͷͰɺҰͭͷू໿Λѻ͍ͬͯΔؒ͸Repositoryͷ
    தʹด͡Δ͜ͱ͕Ͱ͖Δɻ
    • ໰୊͸ɺෳ਺ͷू໿ͷߋ৽Λ୯ҰͷτϥϯβΫγϣϯ಺ͰߦΘͳ͚
    Ε͹͍͚ͳ͍࣌
    1. ݁Ռ੔߹ੑͰे෼Ͱ͸ͳ͍͔Λݕ౼͢Δ

    ˠτϥϯβΫγϣϯͷແ͍ੈք΁ʢႈ౳ͳૢ࡞͸ඞཁʣ
    2. ৽͍͠ू໿ͱͯ͠ఆٛ͢Δ

    ˠ͜ΕΛ܁Γฦ͢ͱڊେͳू໿ʹͳͬͯ͠·͏ͷͰ஫ҙ

    View full-size slide

  65. ίωΫγϣϯʹ͍ͭͯ
    • RepositoryΛUseCase૚ʹݶఆ͍ͯ͠ΔͷͰίωΫγϣ
    ϯΦϒδΣΫτ͕ݱΕΔͷ͸͜͜·ͰͰࡁΜͰ͍Δ…
    • ΋͠ɺυϝΠϯαʔϏεͰ΋RepositoryʹΞΫηεͨ͠
    ͍৔߹͸ίωΫγϣϯΛ౉͞ͳ͚Ε͹͍͚ͳ͍͕ɺ͜Ε
    ͸υϝΠϯͷؔ৺Ͱ͸ͳ͍఺ʹ્·ΕΔ
    • implicitͰݱΕΔ෼ʹ͸ڐ༰͢Δʁ
    • ϨΠϠεʔύʔλΠϓʢجఈΫϥεʣʹӅṭ͢Δʁ

    View full-size slide

  66. Ϣʔεέʔεۦಈ։ൃʹ
    ग़ձͬͨ࿩
    ઃܭͷલʹ༧උઃܭΛͯ͠
    ᐆດੑΛഉআ͢Δ

    View full-size slide

  67. ͍͟DDDΛ࣮ફ͠Α͏ͱ͢Δͱ
    • Կ͔Β࢝Ίͯྑ͍͔෼͔Βͳ͍
    • υϝΠϯΤΩεύʔτͱͲ͏࿩ͤ͹ྑ͍͔෼͔Βͳ͍
    • UIແ͠ͰυϝΠϯ͚ͩΛ࿩ͯ͠΋্ख͘఻ΘΒͳ͍
    • ࠷ॳ͔ΒৄࡉͳΫϥεਤΛॻ͜͏ͱͯ͠͠·͏
    • ࢼ͠ʹϞσϧ͚ͩͰ΋ॻ͍ͯΈΔͱࢥ͍ͷ֎ϘϦϡʔϛΟ
    • υϝΠϯϞσϧʢΫϥεਤʣ͔Β࢓༷ΛಡΈऔΔͷ͕ࠔ೉
    • ૝૾ͯ͠ಡΈऔΖ͏ͱ͢Δͱᐆດ͞ʹ௚໘͢Δ
    ㅟ ㅟ ㅟ
    ※ฐࣾࣄྫ͚ͩͰͳ͘ໝ૝΋ؚ·Ε·͢

    View full-size slide

  68. υϝΠϯϞσϧ͚ͩʹ
    ண໨͍ͯ͠Δͱ
    ྲྀΕ͕Θ͔Βͳ͘ͳΔ

    View full-size slide

  69. IUUQCMPHUIMJHIUDPNVODMFCPC
    UIFDMFBOBSDIJUFDUVSFIUNM
    ͲͪΒ΋Ϗδωεϧʔϧ
    6TF$BTF͸
    ΞϓϦέʔγϣϯݻ༗ͷ
    Ϗδωεϧʔϧ

    View full-size slide

  70. Ϣʔεέʔεʢ΍ετʔϦʔʣ
    ʹΑͬͯυϝΠϯϞσϧ͸
    ࢖ΘΕΔ

    View full-size slide

  71. Ϣʔεέʔε೉ຽ

    View full-size slide

  72. ॻ੶
    ʮϢʔεέʔεۦಈ։ൃ࣮ફΨΠυʯ
    • Use Case Driven Object Modeling with UML
    • ICONIXϓϩηεͷղઆຊ
    • ඇৗʹܰշͳޠΓޱʢ͏ͻΌʔͱ͔ग़ͯ͘Δʣ
    • एׯXP൱ఆʢߟ͑ࣗମ͸XPΑΓલ͔Β͋Δʣ
    • ͍͖ͳΓઃܭʹೖΔͷͰ͸ͳͯ͘ɺ·ͣ͸෼ੳΛͪΌΜͱ͠Α͏ɻ
    • ಛʹʮՄೳͳݶΓ؆୯ʹ(DTSTTCPW)ʯͱʮͦΜͳ΋ͷ͸ඞཁͳ͍
    (YAGNI)ʯΛཧ༝ʹ୅ସίʔεʢΤϥʔέʔεʣΛߟྀʹؚΊͳ͍
    ͜ͱ͸ഁ໓΁ͷಓͱ͍ͯ͠Δɻ

    View full-size slide

  73. ·࣮ͩફஈ֊Ͱ͸ͳ͍ͷͰ
    ࠓճ͸঺հ͚ͩɾɾɾ

    View full-size slide

  74. ICONIXϓϩηε͕໨ࢦ͢τίϩ
    • ᐆດ͞Λഉআ͢Δ͜ͱ͕ୈҰ
    • Ͳ͔ͪΒͱ͍͏ͱυΩϡϝϯτେࣄ࿦ௐ
    • ͱݴͬͯ΋ɺʢίʔυϑΝʔετͰ͸ͳ͍ͩ
    ͚Ͱʣ໨తΛୡ੒͢Δ͜ͱʹ஫ྗͯ͠ɺମࡋ
    ΍༨෼ͳ΋ͷΛ࡟͗མͱͨܰ͠ྔͳυΩϡ
    ϝϯτΛਪ঑͍ͯ͠Δɻ

    View full-size slide

  75. ICONIXϓϩηεશମ૾
    ͔͜͜Β࢝·ΔΑ͏ʹ
    ݟ͑Δ͚ΕͲɾɾɾʁ
    ಈతͳϫʔΫϑϩʔͱ
    ੩తͳϫʔΫϑϩʔ͕
    ͋Δ

    View full-size slide

  76. ཁٻϑΣʔζ
    1. ސ٬͔Βେখ༷ʑͳػೳཁٻ͕ग़ͯ͘Δ

    ʢཁٻऩू͸ICONIXͷൣғ֎ɺॻ੶ʹ͸ΞυόΠεܝࡌʣ
    2. υϝΠϯϞσϧͰݴ༿Λ౷Ұ͢Δͱ͜Ζ͔Β࢝ΊΔ
    3. ࢴࣳډʢϓϩτλΠϓʣΛ࢖ͬͯސ٬͔ΒৼΔ෣͍ཁٻΛ
    ฉ͖ग़͢
    4. υϥϑτ൛ͷϢʔεέʔεΛ࡞੒͢Δ
    5. ސ٬ͱҰॹʹϨϏϡʔΛߦ͏
    ㅟ ㅟ ㅟ

    View full-size slide

  77. ෼ੳϑΣʔζ
    1. υϥϑτ൛Ϣʔεέʔε͔Βϩόετωε෼ੳΛߦ͏
    2. ݟམͱͨ͠Ϋϥεͷൃݟ΍ᐆດ͞Λআڈͨ݁͠ՌΛυϝΠϯϞσϧʹ
    ϑΟʔυόοΫ͢Δ
    3. ʢϩόετωεਤதͷʣίϯτϩʔϥʹ໌֬ͳ໊લΛ෇͚Δ

    ˠ͜Ε͕"ৼΔ·͍"ʹͳΔ
    4. υϥϑτ൛ϢʔεέʔεΛॻ͖௚͢
    5. ސ٬ͱҰॹʹϨϏϡʔΛߦ͏
    ㅟ ㅟ ㅟ
    ※෼ੳʙ࣮૷ϑΣʔζ͸Ϣʔεέʔε୯ҐʹΠςϨʔςΟϒʹߦ͏

    View full-size slide

  78. ৄࡉઃܭϑΣʔζ
    1. Ϣʔεέʔεͱϩόετωεਤ͔Βγʔέϯεਤ
    Λ࡞੒͢Δ
    2. γʔέϯεਤΛॻ͖ͳ͕ΒɺυϝΠϯϞσϧʹৼ
    Δ෣͍ΛׂΓ౰ͯɺΫϥεਤ΁సԽ͍ͯ͘͠
    3. σβΠϯύλʔϯͳͲΛ༻͍ͯɺઃܭ্ͷ໰୊ղ
    ܾ΍վળΛߦ͏
    4. ։ൃऀ಺ͰϨϏϡʔΛߦ͏
    ㅟ ㅟ ㅟ ㅟ

    View full-size slide

  79. ࣮૷ϑΣʔζ
    1. ίʔσΟϯάɾ୯ମςετ
    2. Ϣʔεέʔεʹج͍ͮͨ݁߹ςετΛߦ͏
    3. ʢγεςϜςετ΍σϓϩΠʣ
    4. ࣍ͷΠςϨʔγϣϯʹ޲͚ͯɺίʔυϨϏϡʔ
    ͱυϝΠϯϞσϧͷߋ৽Λߦ͏
    5. ෼ੳϑΣʔζʹ໭Γɺ࣍ͷϢʔεέʔεΛਐΊΔ

    View full-size slide

  80. ICONIXϓϩηε͸DDDͷ࣮ફ
    ࣮͸͔͜͜Β
    ࢝·Δ
    υϝΠϯϞσϧΛҭͯΔͨΊʹɺ
    ϢʔεέʔεΛ࢖ͬͯۦಈ͍ͯ͠Δ
    ϢʔεέʔεϞσϧ͸
    ίϯςΩετͷൃݟʹ
    ΋໾ཱͭ
    ϩόετωε෼ੳ౳Λ͠ͳ͕Β
    υϝΠϯϞσϧΛߋ৽

    View full-size slide

  81. ෼ੳͷඞཁੑ
    • DDDͰ͸७ਮͳ෼ੳϞσϧΛ൱ఆ͍ͯ͠Δ
    • ७ਮͳ෼ੳϞσϧ͸ίʔσΟϯά͕࢝·ΔͱࣺͯΒΕͯ͠·͏
    ͜ͱ͕ཧ༝ɻ͕ɺ͜Ε͸։ൃऀͱ෼ੳऀ͕෼͔Ε͍ͯΔલఏ
    • ʮ෼ੳͱઃܭͷؒʹக໋తͳُ྾͕ੜ͡ΔͨΊɺͦΕͧΕͷ
    ࡞ۀͰಘΒΕΔಎ࡯͸ޓ͍ʹ׆͔͞ΕΔ͜ͱ͕ͳ͍ͷͩɻʯ
    • ʮ஌ࣝΛטΈࡅ͘ऀ͸Ϟσϧͱઃܭ͓ΑͼίʔυΛ୯Ұͷ׆ಈ
    ͱͯ͠վྑ͠ଓ͚ΔΠςϨʔςΟϒͳϓϩηεͱͳΔʯ

    (DDD p.46 - 47)

    View full-size slide

  82. DDDͰ͍͏࣮ફతϞσϥ
    ΛϓϩηεԽͨ͠΋ͷ͕ICONIX
    ʢͱߟ͑Δͱ෼͔Γ΍͍͢ʣ

    View full-size slide

  83. –ʮϢʔεέʔεۦಈ։ൃ࣮ફΨΠυʯ1ষத
    “௨ৗɺԿΒ͔ͷઃܭ࡞ۀΛߦΘͳ͍ݶ
    Γɺࣗ෼͕औΓѻ͏ཁٻΛਖ਼͘͠ཧղ͢
    Δ͜ͱ͸Ͱ͖ͳ͍ɻ”

    View full-size slide

  84. શͯͷϢʔεέʔεΛ෼ੳ͠ͳ
    ͚Ε͹͍͚ͳ͍ʁ
    • ͍͖ͳΓશͯͷϢʔεέʔεΛ෼ੳ͢Δඞཁ͸
    ͳ͍ɻICONIXϓϩηε͸1ͭͷϢʔεέʔε
    ͕͋Ε͹ۦಈͤ͞Δ͜ͱ͕Ͱ͖Δɻͱ͸͍
    ͑ɺͨͬͨ̍ͭͷখ͞ͳϢʔεέʔεͰࡁΉι
    ϑτ΢ΣΞͷํ͕ك
    • Ͳ͏΍ͬͯείʔϓΛߜ͍͔ͬͯ͘ʹͭ
    ͍ͯ͸ɺϢʔβʔετʔϦʔϚοϐϯά
    ͕ࢀߟʹͳΓ·͢ɻ

    View full-size slide

  85. XPͱͷؔ܎
    • XP͸͋͘·Ͱ΋ʮՁ஋ɾݪଇɾϓϥΫςΟεʯɻICONIX͸෼ੳ͓
    ΑͼઃܭͷϞσϦϯάϓϩηεͳͷͰɺछʑͷํ๏࿦ʹద༻͠΍͢
    ͍ɻ
    • ʮຊ෺ͷސ٬ࢀՃʯ͕೉͍͜͠ͱΛड़΂͍ͯΔɻͦͷͨΊʹɺϨ
    ϏϡʔΛϓϩηεʹ૊ΈࠐΜͰ͍Δɻ

    ˠνʔϜʹΑͬͯςʔϥϦϯά͢Ε͹ྑ͍
    • ICONIXϓϩηεͰ͸ɺετʔϦʔ͔Β͙͢ίʔυΛॻ͖࢝Ίͳ͍

    ˠνʔϜͷशख़౓΍ن໛ʹΑͬͯςʔϥϦϯά͢Ε͹ྑ͍

    ɹ͔͠͠ɺυϝΠϯ஌ࣝΛ๛෋ʹ΋ͭϓϩάϥϚͷํ͕গͳ͍ݱ࣮

    View full-size slide

  86. Clean Architectureͱͷ਌࿨ੑ
    • "UseCase૚"ͱͦͷ·Μ·ͷ૚͕͋ΔͷͰؔ܎͕෼͔Γ΍͍͢ʢ"ΞϓϦέʔ
    γϣϯαʔϏε"ͱ͍͏ݴ༿ΑΓ͸ྑ͍ͱࢥ͏ɻϢʔεέʔεͱ͍͏ݴ༿Ͱͳ͍
    ͷ͸ɺʢICONIXͳͲΛ࢖Θͳ͍ͱʣৄࡉͳٕज़ཁૉΛೖΕͯ͠·͍΍͍͔͢Β
    Ͱ͸ʁʣ
    • ۩ମతͳϑϨʔϜϫʔΫ΍DB͕ܾ·͍ͬͯͳͯ͘΋։ൃΛਐΊΔ͜ͱ͕Ͱ͖Δ
    • ICONIXϓϩηε͸UseCase૚ͱDomain૚ͷؔ৺ࣄʹ͍ͭͯѻ͏
    • Clean Architecture͸ΞϓϦέʔγϣϯʢUseCase&DomainʣͱΠϯϑϥΛ
    ෼཭͢Δ
    • Hexagonal΍OnionͰ΋ಉ༷

    View full-size slide

  87. ద༻΁ͷߟ࡯̍
    ਖ਼ࣜͳυΩϡϝϯτʹ͠ͳ͍
    • ސ٬ͱʮԿΛͭ͘Δͷ͔ʯΛᐆດ͞Λղফͯ͠߹ҙ͢Δ͜ͱ͕େࣄ
    • ICONIXϓϩηεͰ͸ʮ࡞੒͢ΔυΩϡϝϯτ͸͜ΕͰɺͦΕΛϨ
    Ϗϡʔ͢Δػձ͸͍ͭʯΛ໌֬ʹఆ͍ٛͯ͠Δɻ
    • ਖ਼֬ʹॻ͘͜ͱ͸ਪ঑͍ͯ͠ͳ͍ʢॏްͳυΩϡϝϯτ͸଍
    ᐫʣɻUML࢓༷ʹ४ڌ͢Δඞཁ͸ͳ͍ɻۃ୺ͳ࿩ɺϗϫΠτ
    Ϙʔυͷམॻ͖Ͱ΋ྑ͍ʢͱࢥ͏ʣɻ
    • ॻ੶தͰ͸πʔϧΛ࢖͏͜ͱΛલఏʹɺίʔυͱઃܭΛಉظ͢
    Δ͜ͱ͸ڧ͘ਪ঑͞Ε͍ͯΔɻࢴͱԖච͕Ұ൪ڧ͍͔΋͠Εͳ
    ͍ɻʮΊ΋Ͱ͘͢ʯͱ͔ࢼͯ͠Έ͍ͨɻ

    View full-size slide

  88. ద༻΁ͷߟ࡯̎
    ੔߹ੑཁٻͷݕ౼
    • ސ٬͕ࢀՃ͢ΔϨϏϡʔ͸༧උઃܭϨϏϡʔ·ͰʢγʔέϯεਤҎ
    ߱͸ٕज़త͗͢ΔʣɻؾΛ͚ͭͳ͍ͱϩόετωε෼ੳͷஈ֊Ͱ
    ͸੔߹ੑཁٻͷදݱ·Ͱٴ͹ͳ͍ؾ͕͢Δɻ
    • શͯʹτϥϯβΫγϣϯ͕ඞཁͱ͸ݶΒͣɺ݁Ռ੔߹ੑͰे෼
    ͳέʔε΋ଟ͍͸ͣɻ
    • ༧උઃܭϨϏϡʔͷஈ֊·Ͱʹ੔߹ੑͷཁٻʢϨϕϧʣʹ͍ͭ
    ͯݕ౼ͨ͠ํ͕ྑ͍ͱࢥ͏ɻ
    • "τϥϯβΫγϣϯͷ෼ੳΛ͔ͯ͠ΒͰͳ͍ͱɺू໿ͷઃܭͷྑ
    ͠ѱ͠Λਖ਼͘͠൑அ͢Δ͜ͱ͸Ͱ͖ͳ͍"ʢIDDD p.340-344ʣ

    View full-size slide

  89. ։ൃϓϩηεͷ
    มߋ͸೉͍͠ɾɾɾ
    νʔϜͷܾ·Γʁ
    ձࣾͰنఆ͞Ε͍ͯΔʁ
    ސ٬͔Βࢦఆ͞Ε͍ͯΔʁ

    View full-size slide

  90. –Team Geek
    ʮ5.6 ر๬͸࢒͞Ε͍ͯΔʯΑΓ
    “࠷ॳʹ΍Βͳ͚Ε͹͍͚ͳ͍ͷ͸ɺ࢓ࣄ
    Λୡ੒͢ΔͨΊʹԿ͔Λม͑Δ͜ͱͩɻ”

    View full-size slide

  91. ͦΕͰ΋ਏ͘ͳͬͨΒɾɾɾ

    View full-size slide

  92. XXXXBOUFEMZDPNQSPKFDUT
    ΠϠʔά΢θϯμφʔ

    View full-size slide

  93. ·ͱΊ
    • DDD

    + Clean Architecture

    + Use Case Driven Object Modeling(ICONIX)

    ͷηοτ͸૬ੑ͕ྑͦ͞͏
    • ICONIX͸ܰྔͱ͸͍͑ɺͦͷதͰ΋Ͳ͜·ͰΛ࣮ࢪ͢Δ͔
    ސ٬΍νʔϜͱςʔϥϦϯάͨ͠ํ͕ྑ͍͔΋
    • ֖Λ։͚Ε͹஌͍ͬͯΔਓʹ͸౰ͨΓલ…

    ૣ͘஌Γ͔ͨͬͨ

    ʢଞͷ࣮ફख๏΋͝ଘ஌ͷํ͕͍Βͬ͠ΌΕ͹ޙͰڭ͍͑ͯͩ͘͞ʣ

    View full-size slide

  94. Q & A vol.1
    • Q.Contract૚ͷ༝དྷ͸ʁ

    A.֎ଆͷ૚Ͱ࢖͏ͨΊʹɺ͜ͷϢʔεέʔε͸͜ͷ੹຿͕͋Γ·͢ͱܖ໿͍ͯ͠
    ·͢ɻ͜ͷΠϯλϑΣʔεΛஔ͘૚Ͱ͢ɻαϯϓϧͰ͸লུ͍ͯ͠·͕ͨ͠DTO
    ͷΑ͏ͳϢʔεέʔε͕ඞཁͱ͢Δ΋ͷ΋ؚΈ·͢ɻ
    • Q.CQRSͱͷ਌࿨ੑ͸ʁ

    A.͝ΊΜͳ͍͞ɺ·ͩ໌֬ͳ౴͕͑Ͱ͖ͳ͍Ͱ͢ɻΞʔΩςΫνϟ͸ߏ଄Λͭ͘
    ΔͨΊͷ΋ͷͳͷͰɺద༻Ͱ͖ͳ͍͜ͱ͸ͳ͍ͱࢥ͍ͬͯ·͢ɻ͕ɺޙ൒ͷεϥ
    ΠυͷΑ͏ʹϩοΫΠϯ͞Εͨํָ͕ͳ͜ͱ΋͋Γ·͢ɻ

    Ұ౓Կ͔͠ΒͷϑϨʔϜϫʔΫΛ࢖͑͹ɺجຊ࢖͍ଓ͚ΔΑͶͱ͍͏ߟ͑΋ݱ࣮
    ղͱͯ͠͸ΞϦͳͷͰɺνʔϜɺͻ͍ͯ͸ϓϩμΫτͱͯ͠Ͳ͏͍͏ઓུΛͱΔ
    ͔ɺͰ͢ɻݸਓతʹ͸ϩοΫΠϯ͞ΕͣʹυϝΠϯͷಠཱੑΛอͭಓΛ໛ࡧͨ͠
    ͍Ͱ͢Ͷɻ

    View full-size slide

  95. Q & A vol.2
    • Q.Clean ArchitectureΛಋೖ͢ΔͨΊͷΞυόΠε͸ʁ

    A.͋͘·ͰΞʔΩςΫνϟͳͷͰMVCΛ࠾༻͠·͔͢ʁDCIΛ࠾༻͠·͢
    ͔ʁͱಉ͡ઢͷԆ௕Ͱ͢ɻνʔϜͰཧղ͠΍͍͢΋ͷΛ·ͣ࿩͠߹͏ͷ͸Ͳ
    ͏Ͱ͠ΐ͏͔ʁ్தͰม͑Δͷ͸೉͍͠ͱࢥ͍·͢ɻ

    ·ͣ͸ࠓճͷαϯϓϧΛԼ஍ʹͯ͠ɺҰ͔ͭೋͭϢʔεέʔεΛ࣮૷ͯ͠Έͯ
    ײ֮Λ௫Ήͷ͸ྑ͍͔΋͠Ε·ͤΜɻͨͩ͠ɺCallbackΛ࢖͏ͷ͔Promise
    Λ࢖͏ͷ͔ͷΑ͏ͳςʔϥϦϯά͸ͨ͠ํ͕ྑ͍Ͱ͢ɻϓϥοτϑΥʔϜ΍
    ࠾༻ٕज़ͷ౎߹ͳͲɻ

    ະ஌orܦݧ͕ͳ͚Ε͹ɺখ͞ͳͱ͜Ζ͔Β࢝Ί·͠ΐ͏ɻ࠷খͷܗ͕αϯϓ
    ϧίʔυͰ͢ɻඞཁʹԠͯ͡΍ɺ༧Ί༧ظͰ͖Δ͜ͱΛࡌ͍͖ͤͯ·͠ΐ͏ɻ
    ϕʔεΛ࡞Δ࣌ͷίπ͸ϩδοΫΛ૊Ήਓʹ͜͏ॻ͍ͯཉ͍͠ɺΛ૝૾ͯ͠
    ੍͋͑ͯ໿Λ࡞Δ͜ͱͱࢥ͍·͢ɻ

    View full-size slide

  96. ࢀߟɿDDDฤ
    • ॻ੶ʮΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭʯʢᠳӭࣾʣ
    • ॻ੶ʮ࣮ફυϝΠϯۦಈઃܭʯʢᠳӭࣾʣ
    • ਿຊ ܒ ࢯʮυϝΠϯۦಈઃܭ at DDD.rb #5ʯ
    • ਿຊ ܒ ࢯʮ2ͭͷυϝΠϯϞσϧʕDDDͷؚҙʯ
    • ૿ా ږ ࢯʮ3ि࿈ଓDDDͦͷ1 υϝΠϯۦಈઃܭͷجຊΛཧղ͢Δʯ
    • ૿ా ږ ࢯʮ3ि࿈ଓDDDͦͷ2 ਂ͍Ϟσϧͷ୳ٻ(υϝΠϯۦಈઃܭ ୈ̏෦) ʯ
    • ૿ా ږ ࢯʮ3ि࿈ଓDDDͦͷ3 υϝΠϯۦಈઃܭ ઓུతઃܭ ʯ
    • InfoQʮυϝΠϯۦಈઃܭɾ։ൃͷ࣮ફʯ
    • InfoQʮίϯςΩετϚοϐϯάʹΑΔઓུతυϝΠϯۦಈઃܭʯ
    • InfoQʮShane HastieࢯɺϏδωε՝୊ʹର͢ΔΞδϟΠϧϚΠϯυηοτͷద༻ʹ͍ͭͯޠΔʯ

    View full-size slide

  97. ࢀߟɿClean Architectureฤ
    • ετϥςδοΫνϣΠεʮϨΠϠʔυΞʔΩςΫνϟʯ
    • Alistair Cockburn ࢯʮHexagonal Architectureʯʢ຋༁ɿ෢౻ ࢯʣ
    • Jeffrey Palermo ࢯʮThe Onion Architectureʯ
    • Robert Martin ࢯʮThe Clean Architectureʯʢ຋༁ɿ෢౻ ࢯʣ
    • Thomas PIERRAIN ࢯʮA zoom on the hexagonal/clean/onion architectureʯ
    • InfoQʮυϝΠϯۦಈઃܭͱΦχΦϯΞʔΩςΫνϟʯ
    • InfoQʮΞʔΩςΫνϟͷ໨త͸ҙਤͰ͋ΓɺϑϨʔϜϫʔΫͰ͸ͳ͍ʯ
    • James Coglan ࢯʮ໋ྩܕͷίʔϧόοΫɺؔ਺ܕͷϓϩϛε: Node ͕ҳͨ͠࠷େͷػձʯ(຋༁ɿԬຊ ࢯ)
    • Togetter·ͱΊʮ”໋ྩܕͷίʔϧόοΫɺؔ਺ܕͷϓϩϛε”΁ͷ൓Ԡʢͱͦͷޙʣʯ
    • _kondeiࢯʮ࣋ଓՄೳͳ։ൃΛ໨ࢦ͢ ~ υϝΠϯɾϢʔεέʔεۦಈʢΫϦʔϯΞʔΩςΫνϟʣ + ୯ํ޲ʹ੍ݶͨ͠ॲཧ + FRPʯ
    • ૿ా ږ ࢯʮυϝΠϯϞσϧத৺ͷΞʔΩςΫνϟʯ
    • Android cleanarchitecture

    View full-size slide

  98. ࢀߟɿϢʔεέʔεۦಈ։ൃฤ
    • ॻ੶ʮϢʔεέʔεۦಈ։ൃ࣮ફΨΠυʯʢᠳӭࣾʣ
    • ॻ੶ʮΤΫετϦʔϜϓϩάϥϛϯάୈ2൛৽༁ʯʢΦʔϜࣾʣ
    • ॻ੶ʮϢʔβʔετʔϦʔϚοϐϯάʯʢΦϥΠϦʔδϟύϯʣ
    • ૿ా ږ ࢯʮ࣮ફ ICONIXϓϩηεɿγʔέϯεਤͱΫϥεਤʯ
    • ૿ా ږ ࢯʮ࣮ફ ICONIXϓϩηεɿυϝΠϯۦಈʯ
    • WikipediaʮICONIXϓϩηεʯ
    • EZʮϏδωεཁٻͷٸܹͳมԽʹରԠ͢Δ։ൃϓϩηεͱ͸ʁʯ

    View full-size slide