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

ドメインモデリングの始め方

 ドメインモデリングの始め方

ドメイン駆動設計の考え方は書籍を読むとわかりますが、いざモデリングを実践しようとすると、どこから手を付けていいかわからない、ドメインモデリングの始め方がよくわからないという意見を聞きます。
このスライド資料では、そんな悩みを持つ皆さんに向けて「ドメインモデルを見つけ出し・実装に落とし・改善していく」方法を、できるだけわかりやすく解説します。

かとじゅん

October 31, 2018
Tweet

More Decks by かとじゅん

Other Decks in Programming

Transcript

  1. %%%ຊҎ֎ʹ΋ಡΉͱΑ͍ ͔΋͠Εͳ͍ ຊ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏υϝΠϯɺυϝΠϯϞσϧʹؔ܎͢Δຊ͸̏̔छ΋͋Δ… ๏Qittaʹ·ͱΊͯ͋Γ·͢ ๏໨తΛ࣋ͬͯಡΜͩํ͕Α͍ |[ΦϒδΣΫτࢦ޲ํ๏ংઆʪج൫ฤʫ](https://amzn.to/2SkM2Jw)|δΣʔϜζ

    Ϛʔνϯ|1995/10|487P|̋υϝΠϯͱ͍͏දه͕͋Δʂ|| |[࣮ફUML ύλʔϯʹΑΔ౷ҰϓϩηεΨΠυ ୈ̎൛](https://amzn.to/2OQnbPI)|ΫϨʔάɾϥʔϚϯ|1998/12/31|647P|̋໰୊ྖҬ(domain)Ϟσϧͱ͍͏දه|ϞσϦϯά͕ओମ| |[ϦϑΝΫλϦϯά ϓϩάϥϛϯάͷମ࣭վળςΫχοΫ](https://amzn.to/2RdpOHS)|ϚʔνϯɾϑΝ΢ϥʔ|2000/5/25|423P|̋|[৽૷൛](https://amzn.to/2PSyjrH)͋Γ| |[ιϑτ΢ΣΞΞʔΩςΫνϟ―ιϑτ΢ΣΞ։ൃͷͨΊͷύλʔϯମܥ](https://amzn.to/2Sp2g4j)|F. ϒογϡϚϯ ଞ|2000/12|454P|υϝΠϯ΍υϝΠϯϨΠϠʔͱ͍͏දه͕͋Δ|| |[Ϣʔεέʔεೖ໳―ϢʔβϚχϡΞϧ͔ΒϓϩάϥϜΛ࡞Δ](https://amzn.to/2PWgmbQ)|μάɾϩʔθϯόʔά/έϯυʔϧɾείοτ|2001/11/10|137P|̋|ཁٻ෼ੳͱϞσϦϯά͕ओ ମ| |[ϚϧνύϥμΠϜσβΠϯ](https://amzn.to/2ORRw0g)|δΣʔϜζɾO.ίϓϦϯ|2001/12|291P|̋υϝΠϯͱ͍͏දه͋Γ|[৽૷൛](https://amzn.to/2Rgj4Jf)͋ΓɻϞσϦϯά͕ओମ| |[ΞφϦγεύλʔϯ―࠶ར༻ՄೳͳΦϒδΣΫτϞσϧ](https://amzn.to/2Sk7IVZ)|ϚʔνϯɾϑΝ΢ϥʔ|2002/04|̏̒̌P|υϝΠϯΤΩεύʔτͱ͍͏༻ޠ͕ొ৔͢Δ|| |[ετϦʔϜϥΠϯΦϒδΣΫτϞσϦϯά](https://amzn.to/2PWR25B)|δϧɾχίϥɾଞ|̎̌̌̎/12/20|355P|υϝΠϯͱ͍͏༻ޠ͸ొ৔͢Δ|| |[ΞδϟΠϧϞσϦϯά―XPͱ౷ҰϓϩηεΛิ׬͢ΔϓϥΫςΟε](https://amzn.to/2PZnh3O)|είοτɾWɽΞϯϒϥʔ|2003/8/6|473P|̋υϝΠϯɺυϝΠϯϞσϧɺυϝΠϯί ϯϙʔωϯτͱ͍͏දه|| |[σʔλϕʔεઃܭͷͨΊͷUML](https://amzn.to/2Riadqu)|ΤϦοΫɾJ. φΠόʔάɺ ϩόʔτɾA. ϚΫγϜνϟοΫ|2003/9/13|312P|खݩͷͳ͍ͷͰෆ໌|| |[ΤϯλʔϓϥΠζΞϓϦέʔγϣϯΞʔΩςΫνϟύλʔϯ](https://amzn.to/2PXHuab)|ϚʔνϯɾϑΝ΢ϥʔ|2005/4/20||̋|| |[ΦϒδΣΫτ։ൃͷਆ਷ UML 2.0Λ࢖ͬͨΞδϟΠϧϞσϧۦಈ։ൃͷ͢΂ͯ](https://amzn.to/2OSAU8N)|είοτɾΞϯϒϥʔ|2005/7/25|571P|̋|| |[ϏδωεύλʔϯʹΑΔϞσϧۦಈઃܭ](https://amzn.to/2RhKvmi)|ύϕϧϑϧʔϏʔ/Τεύʔ Ωʔϯ/ΫϦενϟϯɾόΠϒγΣϥʔ|2007/8/9|408P|̋|| |[ΦϒδΣΫτσβΠϯ](https://amzn.to/2OPMTnl)|ϨϕοΧɾϫʔϑεϒϥοΫ|2007/9/13|488P|̋|| |[Ϣʔεέʔεۦಈ։ൃ࣮ફΨΠυ](https://amzn.to/2PTSsO0)|μάɾϩʔθϯόʔά/ϚοτɾεςϑΝϯ|2007/10/6|512P|̋|ཁٻ෼ੳͱϞσϦϯά͕ओମ| |[δΣωϨʔςΟϒϓϩάϥϛϯά](https://amzn.to/2OOQzFL)|ΫγγϡτϑɾνϟϧωοΩ|2008/4/21|776P|̋|| |[ΞδϟΠϧιϑτ΢ΣΞ։ൃͷԞٛ ୈ2൛ ΦϒδΣΫτࢦ޲։ൃͷਆ਷ͱঊͷٕ](https://amzn.to/2OQCho7)|ϩόʔτɾC. Ϛʔνϯ|2008/7/1|712P|υϝΠϯΫϥε|| |[ThoughtWorksΞϯιϩδʔ――ΞδϟΠϧͱΦϒδΣΫτࢦ޲ʹΑΔιϑτ΢ΣΞΠϊϕʔγϣϯ](https://amzn.to/2OTzQl2)|ThoughtWorks|2008/12/27|276P|̋|| |[ΞʔτɾΦϒɾΞδϟΠϧ σϕϩοϓϝϯτ ―૊৫Λ੒ޭʹಋ͘ΤΫετϦʔϜϓϩάϥϛϯά](https://amzn.to/2Rl6etz)|δΣʔϜεɾγϣΞɺ ΫϩϚνοΫ|2009/2/18|464P|◦ϢϏ Ωλεݴޠ΋ొ৔͢Δ|| |[ΞʔΩςΫτͷ৹ඒ؟](https://amzn.to/2SgHPqa)|ഡݪ ਖ਼ٛ|2009/3/3|240P|̋|| |[Clean Code ΞδϟΠϧιϑτ΢ΣΞୡਓͷٕ](https://amzn.to/2EPRRvF)|ϩόʔτɾC. Ϛʔνϯ|2009/5/28|528P|̋υϝΠϯɺDSLͱ͍͏දه͕͋Δ|[৽૷൛ʁ](https://amzn.to/ 2yDTzL5)͕͋Δ| |[Domain Driven DesignʢυϝΠϯۦಈઃܭʣ Quickly ೔ຊޠ൛](https://www.infoq.com/jp/minibooks/domain-driven-design-quickly)|Abel Avram ࢯͱ Floyd Marinescu ࢯ|̎̌̌̕/6/7|| ̋|ϞσϦϯά͕ओମ |[ϨΨγʔίʔυվળΨΠυ](https://amzn.to/2Sj1GF4)|ϚΠέϧɾCɽϑΣβʔζ|2009/7/14|472P|υϝΠϯΫϥεͱ͍͏දݱ|| |[ΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭ](https://amzn.to/2RhJWJc)|ΤϦοΫɾΤϰΝϯε|2011/4/8|576P|̋|ϞσϦϯά͕ओମ| |[UMLϞσϦϯάͷຊ࣭ ୈ2൛](https://amzn.to/2Rf3bTk)|ࣇۄ ެ৴|2011/5/26|296P|υϝΠϯϞσϦϯάͱؔ࿈͕͋Δ|| |[αʔϏεσβΠϯύλʔϯ SOAP/WSDLͱRESTful WebαʔϏεͷجຊతͳઃܭιϦϡʔγϣϯ](https://amzn.to/2yArHHM)|Robert Daigneau|2012/8/24|320P|खݩʹͳ͍ͷͰෆ໌|| |[૊৫ύλʔϯ](https://amzn.to/2RgnsYJ)|δΣʔϜζɾO.ίϓϦϯ|2013/8/6|583P|υϝΠϯͱ͍͏༻ޠ͸ొ৔͢Δ|| |[Ϟσϧϕʔεཁ݅ఆٛςΫχοΫ](https://amzn.to/2ReTDIc)|ਆ࡚ ળ࢘|2013/9/24|415P|̋|ϞσϧΛ࢖ͬͨཁ݅ఆ͕ٛओମ| |[࣮ફυϝΠϯۦಈઃܭ](https://amzn.to/2ReMTKo)|ϰΝʔϯɾϰΝʔϊϯ|2015/3/17|616P|̋|ϞσϧΛ࣮૷ʹ൓ө͢Δ͜ͱ͕ओମ| |[ɽ̣̩̚ͷΤϯλʔϓϥΠζΞϓϦέʔγϣϯΞʔΩςΫνϟɹୈ̎൛](https://amzn.to/2Sjkrs7)|ΞϯυϨΞαϧλϨϩ/σΟϊΤεϙγτ|2015/6/4|432P|̋|ϞσϧΛ࣮૷ʹ൓ө͢Δ ͜ͱ͕ओମ| |[ϏϤϯυ ιϑτ΢ΣΞ ΞʔΩςΫνϟ](https://amzn.to/2RdlQiz)|ϧʔΫɾϗϑϚϯ/Ԭᖒ ༟ೋ|2015/10/2|368P|̋|| |[ϚΠΫϩαʔϏεΞʔΩςΫνϟ](https://amzn.to/2OR4VFC)|αϜχϡʔϚϯ|2016/2/26|344P|දه͸ಛʹͳ͍͕ɺDDDͱͷ໌֬ͳؔ࿈͕͋Δ|| |[ϓϦϯγϓϧ Φϒ ϓϩάϥϛϯά3೥໨·Ͱʹ਎ʹ͚͍ͭͨҰੜ໾ཱͭ101ͷݪཧݪଇ](https://amzn.to/2EQtIoS)|্ా ܄|2016/3/23|304P|̋υϝΠϯۦಈઃܭͱؔ࿈͢ΔίϥϜ͋Γ|| |[Functional and Reactive Domain Modeling](https://amzn.to/2EJuHY4)|Debasish Ghosh|2016/10/24|320P|◦|| |[ϨΨγʔιϑτ΢ΣΞվળΨΠυ](https://amzn.to/2Rez52E)|ΫϦεɾόʔνϟϧ|2016/11/11|264P|̋|| |[Θ͔ΔʂυϝΠϯۦಈઃܭ ʙ΋ͪͪ͜ΌΜͷେ๯ݥʙʲC91৽ץʳ](https://booth.pm/ja/items/392260)|͋Μ͍͟Ώ͖,ͻͭ͡|̎̌̍̒/̍̎/̎̕||̋|ϞσϦϯά͕ओମ| |[ݱ৔Ͱ໾ཱͭγεςϜઃܭͷݪଇ ʙมߋΛָͰ҆શʹ͢ΔΦϒδΣΫτࢦ޲ͷ࣮ફٕ๏](https://amzn.to/2SkJlI2)|૿ా ྃ|2017/7/5|422P|̋|ϞσϦϯά͕ओମ| |[ΞϓϦέʔγϣϯΞʔΩςΫνϟઃܭύλʔϯ](https://amzn.to/2ONirKC)|੪౻ݡ࠸|2017/10/12|893P|̋υϝΠϯΦϒδΣΫτͱ͍͏දهͷํ͕ଟ͍|| |[Clean Architecture ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ](https://amzn.to/2RhNr2i)|ϩόʔτɾC. Ϛʔνϯ|2018/7/27|469P|̋υϝΠϯΦϒδΣΫτͱ͍͏දهͷํ͕ଟ͍|| FYI
  2. ཁ݅ఆٛͱઃܭͷཁૉ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork      

                     /  RDRA
  3. ΋ͬͱϥΠτ΢ΣΠτʹ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ ཁٻϞσϧʹUSMͷόοΫϘʔϯ ๏ ར༻γʔϯ/ۀ຿ϑϩʔ=USMͷ৔໘ ๏ ϢʔεέʔεϞσϧʹUSMͷετʔϦ

    ๏ Ծઆ ๏ ʮίϯςΩετϞσϧʴϢʔβετʔϦϚοϐϯάʴ֓೦Ϟσϧʯ Ͱ΋ಉ͡Α͏ͳ੒Ռ͕ಘΒ ΕΔͷͰ͸ͳ͍͔ɻ͔ͳΓϥΠτ΢ΣΠτʹͳΓͦ͏ͳؾ͕͠·͢ɻ ๏ ίϛϡχέʔγϣϯͱͯ͠͸USMͰे෼ʹ୅༻Ͱ͖Δ͕ɺֆਤͱͯ͠࢒͢ͱͳΔͱซ༻͢ΔՄ ೳੑ͋Γ ఏҊ
  4. υϝΠϯΛִ཭͢Δ  υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ ΫϦʔϯΞʔΩςΫνϟͰ͋ͬͯ΋ɺ υϝΠϯ૚͕Ͳͷ૚͔Β΋ಠཱ͍ͯ͠ Δ͜ͱ υϝΠϯ૚

    Ϣʔεέʔε૚ ΠϯλʔϑΣΠε૚ API Repository OutputPort Member UseCase MemberUseCase InputPort RepositoryImpl Event DDD
  5. υϝΠϯ஌ࣝΛίʔυͰදݱ͢Δ  υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ ͓ۚ͸਺஋Ͱ͸ͳ͍ɻ͓ۚͷྔͱ௨՟୯Ґʹ ؔ࿈͢ΔυϝΠϯ஌ࣝ ๏ ಺෦ͷଐੑΛ؆୯ʹ๫࿐͍ͯͯ͠͸ɺଘࡏҙ

    ͕ٛബΕΔ ๏ ൑அɾՃ޻ɾܭࢉ͢ΔৼΔ෣͍Λఏڙ͢Δ ๏ Getter/SetterͷཏྻͰ͸υϝΠϯ஌ࣝΛڽू Ͱ͖ͳ͍ɻ͜͏͍͏ৼΔ෣͍͸Ͳ͏΍ͬͯந ग़͢Δͷ͔ʁ
  6. Ϣʔεέʔεهड़Λ#$&ʹ෼ྨ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ BCEεςϨΦλΠϓΛϢʔεέʔεهड़্ͷީิ༻ޠʹৼ͓ͬͯ͘(Ճ౻ಠࣗͷํ๏) ๏ ʮγεςϜ͸ɺΠϕϯτΧςΰϦ(E)ʹجͮ͘ΠϕϯτϦετ(E)ΛؚΉΠϕϯτҰཡϖʔδ(B) Λදࣔ͢Δ(C)ʯ ๏

    ʮγεςϜ͸ɺࢀՃऀ(E)ͱͯ͠ݱࡏͷϩάΠϯதͷϢʔβ(E)ΛΠϕϯτ(E)ʹ௥Ճ͢Δ(C)ʯ  (   )   ( ) "&(   ) !&(%) $ # ICONIX ෼ੳ/ઃܭ
  7. ϩόετωε෼ੳ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ ৄࡉઃܭͷͨΊͷ༧උઃܭɻγʔέ ϯεਤ΍Ϋϥεਤͷ࡞੒Λޮ཰Խ͢ Δ ๏ ໊ࢺʔಈࢺʔ໊ࢺͷܗࣜͰϢʔε

    έʔεهड़ΛύλʔϯԽ͢Δ ๏ Ϣʔεέʔεهड़ͷෆ଍Λൃݟ ๏ ࢓༷ͷൈ͚࿙ΕΛൃݟ ๏ ୅ସίʔεͷݕূ ๏ Ϣʔεέʔεهड़΁ͷϑΟʔυόο Ϋ ICONIX ෼ੳ/ઃܭ
  8. γʔέϯεਤ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ ੹຿Λج४ʹɺίϯτϩʔϧΛͲͷΤϯςΟςΟʹׂΓ౰ͯΔ͔Λߟ͑Δ ๏ ͦͷΤϯςΟςΟͱ͔Կ͔ ๏ ͦͷίϯτϩʔϧ͸ɺͲͷΤϯςΟςΟͷ੹຿(൑அ/Ճ޻/ܭࢉɻӬଓԽҎ֎)ͱͳΔ΂͖͔ʁ

    ϩόετωε෼ੳͰಘΒΕͨཁૉΛ഑ஔ ࠷ऴతͳ෼ੳ݁Ռ ICONIX ෼ੳ/ઃܭ ๏ ׳ΕΕ͹CRUDҎ֎ͷίϯτϩʔϧΛݟ͚ͭग़ ͠ɺͦΕʹؔ࿈͢ΔɺυϝΠϯΦϒδΣΫτΛ ΠϝʔδͰ͖ΔΑ͏ʹͳΔ
  9. &WFOU4UPSNJOH υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork ๏ ࠷ۙ࿩୊ͷυϝΠϯ෼ੳͷख๏ɻEric͞ Μ΋ڧྗͳํ๏ͩͱೝΊ͍ͯΔ ๏ ू໿ͱͦͷৼΔ෣͍Λݟ͚ͭΔϓϩηε ๏

    υϝΠϯΠϕϯτΛ࡞Δ ๏ υϝΠϯΠϕϯτΛൃੜͤ͞ΔίϚϯ υΛ௥Ճ͢Δ ๏ ίϚϯυΛૹ৴͢ΔΞΫλʔΛ௥Ճ͢ Δ ๏ ͜ΕΒͷ৚݅ʹ;͞Θ͍͠ू໿Λߟ͑ Δ ๏ λΠϜϥΠϯΛ࡞ͬͯ෼ੳ͢Δɻ ๏ ॻ੶(ࣥචத) Alberto Brandolini ๏ https://leanpub.com/ introducing_eventstorming λΠϜϥΠϯ FYI
  10. ͠ͳ΍͔ઃܭͱ͸ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork DDD ҙਤͷ໌֬ͳΠϯλʔϑΣΠε ද໌ ෭࡞༻ͷͳ͍ؔ਺ ๏ ϞσϧΛվྑ͢Δ͜ͱͰɺιϑτ΢ΣΞͷ֦ு΍มߋʹ଱͑ΒΕΔΑ͏ʹ͠ɺੜ࢈ੑΛ޲্ͤ͞Δ͜ͱ͕

    Ͱ͖Δઃܭ ֓೦ͷྠֲ ดͨ͡ૢ࡞ ಠཱͨ͠Ϋϥε ઃܭΛ༧ଌՄೳʹ ઃܭΛߴ͍ڽूੑʹ ෼ੳ/ઃܭ ๏ ࣌ؒͷ౎߹ͰɺશͯΛ঺հͰ͖ͳ͍ͷͰɺҰ͚ͭͣͭͩ঺հ͠·͢
  11. ෭࡞༻ͷͳ͍ؔ਺ύλʔϯͷޮՌ υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork DDD ๏ ෭࡞༻͕൐͏ϩδοΫΛɺ෭࡞༻͕൐Θͳ͍(໰߹ͤͱͯ͠ͷ)ؔ਺ͱɺ෭࡞༻Λ൐͏໋ྩΛ෼͚ͯ༻͍Δ͜ ͱͰɺ෭࡞༻Λ҆શʹہॴԽ͢Δ͜ͱ͕Ͱ͖Δ ๏ ҎԼʹࣔ͢Α͏ͳಋೖͷޮՌ͕͋Δ(DDDҾ༻)

    ๏ ৽ͨʹಋೖ͞ΕͨPigment Color͸ʮ෭࡞༻ͷͳ͍ؔ਺ʯΛఏڙ͠ɺͦͷ݁Ռ͸ཧղ͠΍͘͢ɺςετ͠ ΍͘͢ɺ҆શʹ࢖͏͜ͱ͕Ͱ͖ɺଞͷૢ࡞ͱ૊Έ߹Θͤ΍͍͢Α͏ʹͳ͍ͬͯΔɻ ๏ ৭ͷ߹੒ʹؔ͢ΔෳࡶͳϩδοΫ͸׬શʹΧϓηϧԽ͞Ε͓ͯΓɺ։ൃऀ͕͜ͷΫϥεΛ࢖͏ࡍʹ͸࣮૷ Λཧղ͢Δඞཁ΋ͳ͍ɻ
  12. ดͨ͡ૢ࡞ $-0463&0'01&3"5*0/4 υϝΠϯϞσϦϯάͷ࢝Ίํ © ChatWork DDD ๏ Ճࢉ(1 + 1

    = 2)͸ɺ࣮਺ͷू߹ͷԼͰ”ด͍ͯ͡ Δ” ๏ Ϟδϡʔϧͷڽू౓ΛߴΊΔ͜ͱ͕Ͱ͖Δ ๏ ͜ͷύλʔϯ͸ɺ਺ֶతͳੑ࣭Λར༻͍ͯ͠Δ ๏ Ͳ͏͢Δ͔ʁ ๏ ໭Γ஋ͷܕ͕ɺҾ਺ͷܕͱಉ͡ʹ͢Δ