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

65cc101435ac36057f2a2c80244c4c6e?s=128

Yoshitaka Okuda

March 20, 2016
Tweet

Transcript

  1. 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
  2. 3.

    Agenda • υϝΠϯۦಈઃܭʢDDDʣ͓͞Β͍ • Clean Architectureͱ͸Կ͔ • DDD + Clean

    Architectureମݧஊ • Ϣʔεέʔεۦಈ։ൃʢICONIXϓϩηεʣʹ ग़ձͬͨ࿩
  3. 7.

    ݴ༿ͷఆٛʢݪଇʣ • υϝΠϯʢDomainʣ • Ϗδωεશମͷ໰୊ྖҬͦͷ΋ͷͷ͜ͱɻιϑτ΢ΣΞͰղܾ͢Δͷ͸ɺ͜ͷҰ෦ɻ • υϝΠϯϞσϧʢDomain Modelʣ • υϝΠϯʹରͯ͠ɺͦͷղܾࡦʢιϦϡʔγϣϯʣΛϞσϧԽͨ͠΋ͷɻ

    • υϝΠϯΤΩεύʔτʢDomain Expertʣ • υϝΠϯʹਫ਼௨͍ͯ͠ΔਓɻҰਓͰ͋Δ͜ͱ΋͋Ε͹ෳ਺ਓͰ͋Δ͜ͱ΋͋Δɻ • ίΞυϝΠϯʢCore Domainʣ • υϝΠϯ͸͍͔ͭ͘ͷྖҬʹ෼ׂ͢Δ͜ͱ͕ଟ͍ɻ͜ͷ࣌ɺҰ൪ϏδωεՁ஋ͷߴ͍ྖ ҬΛίΞυϝΠϯͱ͍͏ɻ࣌ؒ΍ਓ͸༗ݶͳͷͰίΞυϝΠϯΛݟ͚ͭͯɺͦ͜ʹ஫ྗ ͢Δ͜ͱ͕ॏཁɻ
  4. 8.

    ݴ༿ͷఆٛʢݪଇʣ • ϢϏΩλεݴޠʢUbiquitous Languageʣ • ίʔυΛॻ͍͍ͯΔͱΦϨΦϨ໋໊Λ͕ͪ͠ɻ͢ΔͱɺυϝΠϯΤΩεύʔτ ͱ࿩Λ͢Δͱ͖ʹݴ༿ͷ຋༁͕ൃੜ͢Δɻ͜͏ͳΔͱɺυϝΠϯΤΩεύʔτ ͷඳ͘Ϟσϧͱίʔυ͕ဃ཭͍ͯͬͯ͠͠·͏ͷͰɺυϝΠϯΤΩεύʔτΛ ؚΉνʔϜશମͰಉ͡ݴ༿Λ࢖͏Α͏ʹ߹ҙ͢Δɻ •

    ڥք͚ͮΒΕͨίϯςΩετʢBounded Contextʣ • จ຺ʢίϯςΩετʣʹΑͬͯɺಉ͡ݴ༿ͳͷʹҟͳΔҙຯʹͳΔ͜ͱ͕͋Δɻ υϝΠϯϞσϧ͸େ͖͘ͳΓ͕ͪͳͷͰɺҰ؏ੑΛอͬͨ··εέʔϧ͢Δʹ ͸ɺίϯςΩετͷڥքΛϋοΩϦͤͯ͞ҙຯͷมΘΒͳ͍৔ॴΛ࡞Δɻίϯ ςΩετϚοϓͱ͍͏πʔϧΛ࢖ͬͨΓ͢Δɻ
 InfoQʮίϯςΩετϚοϐϯάʹΑΔઓུతυϝΠϯۦಈઃܭʯΛࢀর
  5. 9.

    υϝΠϯͱίϯςΩετͷؔ܎ υϝΠϯ ίϯςΩετ αϒυϝΠϯ ίΞυϝΠϯ • ఺ઢɿ
 υϝΠϯڥք • ੺࣮ઢɿ


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

    ݴ༿ͷఆٛʢ࣮ફʣ • ΤϯςΟςΟʢEntityʣ • ʢޡղΛڪΕͣʹݴ͑͹ʣҰൠʹ૝૾͢ΔϞσϧͷجຊ୯ҐɻϥΠϑαΠΫϧ ͕͋Δɻ • ू໿ʢAggregateʣ • ͍͔ͭ͘ͷΤϯςΟςΟؒͰ੔߹ੑΛอͨͳ͚Ε͹Ϟσϧͱͯ͠੒ཱ͠ͳ͍৔

    ߹ʢྫ͑͹ɺ஫จͱ஫จ໌ࡉʣ͕͋Δɻ͜ΕΒͷΤϯςΟςΟΛଋͶͨͱ͖ɺ ͦͷϧʔτʹҐஔ͢ΔΤϯςΟςΟΛू໿ͱݺͿɻ • ஋ΦϒδΣΫτʢValue Objectʣ • ϥΠϑαΠΫϧ͸ແ͘ෆมͷΦϒδΣΫτɻϢϏΩλεݴޠͰఆٛ͞Εͨݴ༿ ͱৼΔ෣͍Λ࣋ͭ͜ͱͰυϝΠϯϞσϧ͕๛͔ʹͳΔɻ
  7. 11.

    ݴ༿ͷఆٛʢ࣮ફʣ • υϝΠϯαʔϏεʢDomain Serviceʣ • ෳ਺ͷΤϯςΟςΟʹ·͕ͨΔৼΔ෣͍ͳͲɺΤϯςΟςΟ͕࣋ͭʹ͸ద͞ ͳ͍ৼΔ෣͍Λఆٛͨ͠υϝΠϯΦϒδΣΫτɻঢ়ଶΛ࣋ͬͯ͸͍͚ͳ͍ɻ • ϑΝΫτϦʢFactoryʣ •

    ෳࡶͳΦϒδΣΫτ΍AggregateΛੜ੒͢ΔͨΊͷ࣮૷ύλʔϯɻΤϯςΟ ςΟͷϥΠϑαΠΫϧͷى఺ʹͳΔɻ • ϦϙδτϦʢRepositoryʣ • ΤϯςΟςΟͷϥΠϑαΠΫϧʹ్͓͍ͯதʢঢ়ଶͷ෮ݩʣͱ࠷ޙʢ࡟আʣ Λ୲͏࣮૷ύλʔϯɻAggregateʹରͯ͠ͷΈ༻ҙ͢Δɻ
  8. 18.

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

    • IDDDຊͰ͸ΠϯϑϥΛ࠷্Ґʹ൓స
 ˠΠϯϑϥͷ֎෦ԽΛਐΊΔͱɺ࣍ ߲Ҏ߱ͷΞʔΩςΫνϟʹͭͳ͕Δ
  9. 19.

    ଞͷΞʔΩςΫνϟ • ϔΩαΰφϧΞʔΩςΫνϟ • Ports & AdaptersΞʔΩςΫνϟ ͱ΋ݴ͏ • த৺ʹApplicationΛஔ͖ɺΠϯϑ

    ϥʢUIɺDBɺetcʣΛ֎ଆʹஔ ͘ɻ྆ऀʹ͸Portͱݺ͹ΕΔޱ͕ ͋ΓɺAdapterʹΑͬͯ઀ଓ͞Ε Δɻ • IDDDຊͰ΋ݴٴ
  10. 20.
  11. 24.

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

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

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

    UI͔Βಠཱ͢Δ
 ㅟ ㅟ ㅟ ㅟ UI͸ɺγεςϜͷ࢒Γͷ෦෼Λมߋ͢Δ͜ͱͳ͘ɺ༰қʹมߋ͢Δ͜ͱ͕Ͱ͖Δɻྫ͑͹ Web UI͔ΒίϯιʔϧUI΁ͱஔ͖׵͑Δ͜ͱ͕Ͱ͖Δɻ • σʔλϕʔε͔Βಠཱ͢Δ
 ㅟ ㅟ ㅟ ㅟ Oracle·ͨ͸SQL ServerɺMongo΍BigTableͱ͍ͬͨNoSQLؚΊɺަ׵Λ༰қʹ͢Δɻ Ϗδωεϧʔϧ͸ɺσʔλϕʔεʹؚΊͳ͍ɻ • ೚ҙͷ֎෦ϦιʔεɺαʔϏε͔Βಠཱ͢Δ
 ㅟ ㅟ ㅟ ㅟ Ϗδωεϧʔϧ͸ɺ୯७ʹ֎ͷੈքʹ͍ͭͯ͸Կ΋஌Δඞཁ͸ͳ͘ɺ΍Γ͍ͨ͜ͱ͚ͩʹ ूத͢Ε͹ྑ͍ɻ
  13. 26.

    Clean Architectureͷར఺͸ʁ • ϔΩαΰφϧʴΦχΦϯɺͦΕͧΕͷ͍͍ͱ͜औΓ͕Clean Architecture • ΞϓϦέʔγϣϯʹ૚Λ༩͑ΠϯϑϥͱΞμϓλͰܨ͙ • ґଘؔ܎نଇ͕໌ࣔ͞Ε͍ͯΔ͜ͱ •

    ୯७ʹਤΛݟͯ෼͔Γ΍͍͢ • Adapter૚͕઀ଓΛ୲ͬͯɺ֎ͱܨ͕ΕΔͷ͸UseCaseʹݶఆ • ૚ͷڥքҧ൓͸DIPͰ๷ࢭ • ໨ࢦͯ͠Δ΋ͷ͸ͲΕ΋ಉ͡ͳͷͰɺνʔϜͰཧղΛಘΒΕ΍͍͢΋ͷΛ ࢖͑͹OK
  14. 29.

    Entities(=Domain) • ϨΠϠʔυΞʔΩςΫνϟͰ͍͏υϝΠϯ૚ • اۀશମͷϏδωεϧʔϧΛΧϓηϧԽ • ϝιουΛ࣋ͭΦϒδΣΫτɺ͋Δ͍͸ɺσʔλߏ଄ͱػೳͷηοτ • DDDຊʹ༷ʑͳύλʔϯऩ࿥ •

    اۀ಺ͷ༷ʑͳΞϓϦέʔγϣϯʹΑͬͯ௕͘࢖ΘΕΔ • ಛఆͷΞϓϦέʔγϣϯͷӡ༻ͷมߋʢྫ͑͹ɺϖʔδφϏήʔγϣϯ΍η ΩϡϦςΟʣͷӨڹΛΤϯςΟςΟʹ༩͑Δ΂͖Ͱ͸ͳ͍ • اۀΛލ͕ͳ͍୯ҰͷΞϓϦέʔγϣϯΛॻ͍͍ͯΔ৔߹ͩͱɺΤϯςΟ ςΟ͸ΞϓϦέʔγϣϯͱີ઀ʹ݁͹Ε͕ͪɻ
  15. 30.

    Use Cases • ϨΠϠʔυΞʔΩςΫνϟͰ͍͏ΞϓϦέʔγϣϯʢαʔϏεʣ૚ • ΞϓϦέʔγϣϯݻ༗ͷϏδωεϧʔϧΛΧϓηϧԽ • γεςϜͷϢʔεέʔεΛ࣮૷͢ΔɻυϝΠϯ΁ͷσʔλͷྲྀΕ Λௐ੔͠ɺ·ͨɺυϝΠϯΦϒδΣΫτ΁ࢦࣔΛग़͢ɻ •

    ͜ͷ૚ͷมߋ͕υϝΠϯ૚ʹӨڹͨ͠ΓɺDB΍UIͷΑ͏ͳ֎෦ ͷมߋʹΑͬͯӨڹΛड͚ͳ͍Α͏ʹ͢Δ͜ͱ͕େࣄɻ • ͔͠͠ɺΞϓϦέʔγϣϯૢ࡞ʹมߋ͕͋Δ৔߹ɺ͜ͷ૚͸Өڹ Λड͚ΔɻϢʔεέʔεͷৄࡉΛมߋ͢ΔͳΒɺ͜ͷ૚ͷҰ෦ͷ ίʔυ͸࣮֬ʹӨڹΛड͚Δ͜ͱʹͳΔɻ
  16. 31.

    Interface Adapters (Controllers/Presenters/Gateways) • ϑϨʔϜϫʔΫͳͲΛ࢖͍ɺ۩ମతͳϝΧχζϜΛ࣮૷͢Δ૚ • ಺ͱ֎ͱͷσʔλʢϑΥʔϚοτʣͷม׵͕ओͳ໾ׂ • Controllerɿ ֎૚͔Βड͚औͬͨσʔλΛ಺૚ͰղऍͰ͖ΔσʔλʢυϝΠϯ

    ΦϒδΣΫτʣʹม׵͢Δɻྫ͑͹ɺϑΥʔϜϦΫΤετΛυϝΠϯΦϒδΣ Ϋτʹม׵ • Presenterɿ ಺૚͔Β఻͑ΒΕͨσʔλΛ֎૚Ͱ࢖༻͢Δܗʹม׵͢Δɻྫ͑ ͹ɺυϝΠϯΦϒδΣΫτΛJSONʹม׵ • GatewayʢDB΍֎෦αʔϏεʣɿ ಺૚ʹ͸۩ମతͳ΍ΓऔΓʹؔ͢Δίʔυ͸ ஔ͔ͳ͍Α͏ʹ͢Δɻྫ͑͹ɺRDBΛ࢖͏࣌ɺSQLͷఆٛ͸͜ͷ૚ʹݶఆ͢Δ
  17. 32.

    Frameworks & Drivers (Web/UI/DB/ExternalInterfaces) • ࠷΋֎ଆͷ૚͸ɺσʔλϕʔε΍WebϑϨʔϜϫʔΫͳͲ ͷπʔϧͰߏ੒͞ΕΔɻ • ͜ͷ૚ʹ઀͢Δ಺ଆͷ૚΁ͭͳ͛ΔͨΊͷάϧʔίʔυ Ҏ্ͷ΋ͷ͸ॻ͔ͳ͍ɻ

    • Web΍UIɺσʔλϕʔεͷΑ͏ͳ۩ମతͳ࣮૷ٕज़ʹ͸ɺ গͳ͔Βͣ֐͕͋Δɻ • มԽ͕ܹ͍͠෦෼Ͱ΋͋ΔͷͰɺ࠷΋֎ଆʹஔ͍ͯަ׵ Λ༰қʹ͓ͯ͘͜͠ͱ͕υϝΠϯΛकΔ͜ͱʹܨ͕Δɻ
  18. 35.

    ·ͱΊ • ඇৗʹγϯϓϧͳϧʔϧͳͷͰ෼͔Γ΍͍͢ • ૚Ͱ෼཭ • େ੾ͳ΋ͷΛ಺ଆʹஔ͘ • ґଘؔ܎نଇʢ಺ଆʹͷΈґଘʣΛकΔ •

    ಠཱੑ͸ςετͷ༰қੑʹ΋ߩݙ͢Δ • ٕज़͕ݹ͘ͳͬͨΒ࠷খݶͷखؒͰަ׵Ͱ͖Δ • ϑϨʔϜϫʔΫΛަ׵͢Δ͜ͱ͸͋ͬͯ΋ɺυϝΠϯ஌ࣝΛަ׵ ͢Δͱ͍͏ͷ͸͋Γಘͳ͍
  19. 38.

    ύοέʔδߏ੒ • Domain(Entities)૚ • Contract૚ • Domain૚ͱͷڮ౉͠
 ʢDIΛ࢖͏ͷͰΠϯλϑΣʔε͸ผʹ͍ͯ͠Δʣ • UseCase૚

    • Adapter૚ • Repositoryͷ࣮૷Ϋϥε΋͜͜ • ʢExternal૚ʣ • ϑϨʔϜϫʔΫ΍ϥΠϒϥϦͷ૚ͱ͍͏Ґஔ͚ͮ ̐૚Ͱͳͯ͘΋0,
  20. 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ʹҕৡ
  21. 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Λฦ͢
  22. 44.

    Output Port trait Callback[Result] {
 
 def onSuccess(result: Result): Unit


    
 def onFailure(t: Throwable): Unit
 } ΞϓϦέʔγϣϯϩδοΫͷΤϥʔ΋ ಛผͳ&YDFQUJPOΛ༻ҙͯ͠ฦ͢Α͏ʹ͍ͯ͠Δ ʢ+BWBͷ׳शʹ͍ۙʣ
  23. 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)
 }
 }
  24. 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 ʹ͢Δ
  25. 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 // ୭ΛͲ͏Ϧʔμʹ͢Δ͔͸υϝΠϯ஌ࣝ
 }
 }
 } ΠϯλϑΣʔεΛ࢖͏ %*ͰґଘΛ୯ํ޲ʹ
  26. 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))
 )
 }
 } ೖྗσʔλ͔Βͷม׵͕੹຿ ͜ͷॻ͖ํʹ͍ͭͯ͸ޙ΄Ͳ
  27. 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))
 }
 }
 } ग़ྗσʔλ΁ͷม׵͕੹຿
  28. 57.

    ୊ࡐ֓ཁ • ϑϩϯτͱAjaxͰ΍ΓऔΓ͢ΔAPIαʔϏε • ݱߦͰ͸RailsͰ࡞ΒΕ͍ͯͯɺࠓճ͸ϦϓϨʔε • ࢓༷͸ݱߦ౿ऻ • Ϟσϧ͸ActiveRecord͔Β୤٫ •

    Scala + Play! Framework • ߴෛՙ • ग़དྷΔݶΓ1౓ͷϦΫΤετʹ͓͞Ί͍ͨ • σʔλετΞͳͲ֎෦Ϧιʔε΁ͷΞΫηε͕ूத @@'MJQEFTL@@
  29. 60.

    DDD + Clean ArchitectureͰ σʔλΞΫηεΛίϯτϩʔϧ༰қʹ • DDDʹै͏ͱRepositoryΛ࢖͏ݸॴ͸ΞϓϦέʔγϣ ϯαʔϏεʢUseCaseʣ͔υϝΠϯαʔϏεʹݶఆ͞ Ε͍ͯ͘ •

    ू໿(Aggregate)͕ϥΠϑαΠΫϧ·Ͱ୲͏ͱ੹຿ ͕େ͖͘ͳΓ͗͢ΔʢIDDD p.254ʣ • ࣗવͱσʔλΞΫηεݸॴ͕෼͔Γ΍͘͢ ※υϝΠϯαʔϏεɿෳ਺ͷΤϯςΟςΟʹ·͕ͨΔৼΔ෣͍ͳͲɺΤϯςΟςΟ͕ ࣋ͭʹ͸ద͞ͳ͍ৼΔ෣͍Λఆٛͨ͠υϝΠϯΦϒδΣΫτ
  30. 61.

    DDD + Clean ArchitectureͰ σʔλΞΫηεΛίϯτϩʔϧ༰қʹ • ࠓͷͱ͜ΖυϝΠϯαʔϏεͰRepositoryΛ࢖͍͍ͨέʔε͸ग़͍ͯ ͳ͍ͷͰɺUseCaseͰͷΈRepositoryΛ࢖͑ΔΑ͏ʹͯ͠ࢼ͍ͯ͠Δ • ҙਤͤͣԿ౓΋ݺͼग़ͯ͠͠·͏Մೳੑ͕͋Δˍ࢖͑Δঢ়ଶͩͱ࢖

    ͍ͨ͘ͳΔͷ͕ਓ৘ͳͷͰActiveRecordͷೋͷ෣͍ʹͳΒͳ͍Α͏ ஫ҙΛ෷͍ͬͯΔ • ґଘؔ܎نଇʹΑͬͯ૚͕ด͡ΒΕ͍ͯΔͷͰɺͲ͜ͰσʔλΞΫ ηε͍ͯ͠Δ͔෼͔Γ΍͘͢ͳͬͨ • σʔλετΞ͕Ұ൪֎ͳͷͰަ׵͕͠΍͘͢ͳͬͨɻElasticsearch ൛ͱDynamo൛ͰύϑΥʔϚϯεൺֱ͔ͯ͠Β࠾༻ΛܾΊΔ౳Մೳ
  31. 64.

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

    ݁Ռ੔߹ੑͰे෼Ͱ͸ͳ͍͔Λݕ౼͢Δ
 ˠτϥϯβΫγϣϯͷແ͍ੈք΁ʢႈ౳ͳૢ࡞͸ඞཁʣ 2. ৽͍͠ू໿ͱͯ͠ఆٛ͢Δ
 ˠ͜ΕΛ܁Γฦ͢ͱڊେͳू໿ʹͳͬͯ͠·͏ͷͰ஫ҙ
  32. 67.

    ͍͟DDDΛ࣮ફ͠Α͏ͱ͢Δͱ • Կ͔Β࢝Ίͯྑ͍͔෼͔Βͳ͍ • υϝΠϯΤΩεύʔτͱͲ͏࿩ͤ͹ྑ͍͔෼͔Βͳ͍ • UIແ͠ͰυϝΠϯ͚ͩΛ࿩ͯ͠΋্ख͘఻ΘΒͳ͍ • ࠷ॳ͔ΒৄࡉͳΫϥεਤΛॻ͜͏ͱͯ͠͠·͏ •

    ࢼ͠ʹϞσϧ͚ͩͰ΋ॻ͍ͯΈΔͱࢥ͍ͷ֎ϘϦϡʔϛΟ • υϝΠϯϞσϧʢΫϥεਤʣ͔Β࢓༷ΛಡΈऔΔͷ͕ࠔ೉ • ૝૾ͯ͠ಡΈऔΖ͏ͱ͢Δͱᐆດ͞ʹ௚໘͢Δ ㅟ ㅟ ㅟ ※ฐࣾࣄྫ͚ͩͰͳ͘ໝ૝΋ؚ·Ε·͢
  33. 73.

    ॻ੶ ʮϢʔεέʔεۦಈ։ൃ࣮ફΨΠυʯ • Use Case Driven Object Modeling with UML

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

    ద༻΁ͷߟ࡯̎ ੔߹ੑཁٻͷݕ౼ • ސ٬͕ࢀՃ͢ΔϨϏϡʔ͸༧උઃܭϨϏϡʔ·ͰʢγʔέϯεਤҎ ߱͸ٕज़త͗͢ΔʣɻؾΛ͚ͭͳ͍ͱϩόετωε෼ੳͷஈ֊Ͱ ͸੔߹ੑཁٻͷදݱ·Ͱٴ͹ͳ͍ؾ͕͢Δɻ • શͯʹτϥϯβΫγϣϯ͕ඞཁͱ͸ݶΒͣɺ݁Ռ੔߹ੑͰे෼ ͳέʔε΋ଟ͍͸ͣɻ •

    ༧උઃܭϨϏϡʔͷஈ֊·Ͱʹ੔߹ੑͷཁٻʢϨϕϧʣʹ͍ͭ ͯݕ౼ͨ͠ํ͕ྑ͍ͱࢥ͏ɻ • "τϥϯβΫγϣϯͷ෼ੳΛ͔ͯ͠ΒͰͳ͍ͱɺू໿ͷઃܭͷྑ ͠ѱ͠Λਖ਼͘͠൑அ͢Δ͜ͱ͸Ͱ͖ͳ͍"ʢIDDD p.340-344ʣ
  35. 94.

    ·ͱΊ • DDD
 + Clean Architecture
 + Use Case Driven

    Object Modeling(ICONIX)
 ͷηοτ͸૬ੑ͕ྑͦ͞͏ • ICONIX͸ܰྔͱ͸͍͑ɺͦͷதͰ΋Ͳ͜·ͰΛ࣮ࢪ͢Δ͔ ސ٬΍νʔϜͱςʔϥϦϯάͨ͠ํ͕ྑ͍͔΋ • ֖Λ։͚Ε͹஌͍ͬͯΔਓʹ͸౰ͨΓલ…
 ૣ͘஌Γ͔ͨͬͨ
 ʢଞͷ࣮ફख๏΋͝ଘ஌ͷํ͕͍Βͬ͠ΌΕ͹ޙͰڭ͍͑ͯͩ͘͞ʣ
  36. 95.
  37. 96.

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

    Q.CQRSͱͷ਌࿨ੑ͸ʁ
 A.͝ΊΜͳ͍͞ɺ·ͩ໌֬ͳ౴͕͑Ͱ͖ͳ͍Ͱ͢ɻΞʔΩςΫνϟ͸ߏ଄Λͭ͘ ΔͨΊͷ΋ͷͳͷͰɺద༻Ͱ͖ͳ͍͜ͱ͸ͳ͍ͱࢥ͍ͬͯ·͢ɻ͕ɺޙ൒ͷεϥ ΠυͷΑ͏ʹϩοΫΠϯ͞Εͨํָ͕ͳ͜ͱ΋͋Γ·͢ɻ
 Ұ౓Կ͔͠ΒͷϑϨʔϜϫʔΫΛ࢖͑͹ɺجຊ࢖͍ଓ͚ΔΑͶͱ͍͏ߟ͑΋ݱ࣮ ղͱͯ͠͸ΞϦͳͷͰɺνʔϜɺͻ͍ͯ͸ϓϩμΫτͱͯ͠Ͳ͏͍͏ઓུΛͱΔ ͔ɺͰ͢ɻݸਓతʹ͸ϩοΫΠϯ͞ΕͣʹυϝΠϯͷಠཱੑΛอͭಓΛ໛ࡧͨ͠ ͍Ͱ͢Ͷɻ
  38. 97.

    Q & A vol.2 • Q.Clean ArchitectureΛಋೖ͢ΔͨΊͷΞυόΠε͸ʁ
 A.͋͘·ͰΞʔΩςΫνϟͳͷͰMVCΛ࠾༻͠·͔͢ʁDCIΛ࠾༻͠·͢ ͔ʁͱಉ͡ઢͷԆ௕Ͱ͢ɻνʔϜͰཧղ͠΍͍͢΋ͷΛ·ͣ࿩͠߹͏ͷ͸Ͳ ͏Ͱ͠ΐ͏͔ʁ్தͰม͑Δͷ͸೉͍͠ͱࢥ͍·͢ɻ


    ·ͣ͸ࠓճͷαϯϓϧΛԼ஍ʹͯ͠ɺҰ͔ͭೋͭϢʔεέʔεΛ࣮૷ͯ͠Έͯ ײ֮Λ௫Ήͷ͸ྑ͍͔΋͠Ε·ͤΜɻͨͩ͠ɺCallbackΛ࢖͏ͷ͔Promise Λ࢖͏ͷ͔ͷΑ͏ͳςʔϥϦϯά͸ͨ͠ํ͕ྑ͍Ͱ͢ɻϓϥοτϑΥʔϜ΍ ࠾༻ٕज़ͷ౎߹ͳͲɻ
 ະ஌orܦݧ͕ͳ͚Ε͹ɺখ͞ͳͱ͜Ζ͔Β࢝Ί·͠ΐ͏ɻ࠷খͷܗ͕αϯϓ ϧίʔυͰ͢ɻඞཁʹԠͯ͡΍ɺ༧Ί༧ظͰ͖Δ͜ͱΛࡌ͍͖ͤͯ·͠ΐ͏ɻ ϕʔεΛ࡞Δ࣌ͷίπ͸ϩδοΫΛ૊Ήਓʹ͜͏ॻ͍ͯཉ͍͠ɺΛ૝૾ͯ͠ ੍͋͑ͯ໿Λ࡞Δ͜ͱͱࢥ͍·͢ɻ
  39. 98.

    ࢀߟɿDDDฤ • ॻ੶ʮΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭʯʢᠳӭࣾʣ • ॻ੶ʮ࣮ફυϝΠϯۦಈઃܭʯʢᠳӭࣾʣ • ਿຊ ܒ ࢯʮυϝΠϯۦಈઃܭ at

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

    ࢀߟɿ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
  41. 100.

    ࢀߟɿϢʔεέʔεۦಈ։ൃฤ • ॻ੶ʮϢʔεέʔεۦಈ։ൃ࣮ફΨΠυʯʢᠳӭࣾʣ • ॻ੶ʮΤΫετϦʔϜϓϩάϥϛϯάୈ2൛৽༁ʯʢΦʔϜࣾʣ • ॻ੶ʮϢʔβʔετʔϦʔϚοϐϯάʯʢΦϥΠϦʔδϟύϯʣ • ૿ా ږ

    ࢯʮ࣮ફ ICONIXϓϩηεɿγʔέϯεਤͱΫϥεਤʯ • ૿ా ږ ࢯʮ࣮ફ ICONIXϓϩηεɿυϝΠϯۦಈʯ • WikipediaʮICONIXϓϩηεʯ • EZʮϏδωεཁٻͷٸܹͳมԽʹରԠ͢Δ։ൃϓϩηεͱ͸ʁʯ