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

what is model?

to4iki
January 17, 2017

what is model?

"モデル"という言葉を様々な観点から考えてみる

to4iki

January 17, 2017
Tweet

More Decks by to4iki

Other Decks in Technology

Transcript

  1. Ϟσϧͱ͍͏ݴ༿͸ᐆດ • ҙຯ͕޿͗͢Δ • ͨͩͷσʔλΛ֨ೲ͢Δശͱͯ͠ଘࡏ͢Δέʔε΋୔ࢁΈ͖ͯͨ • ϏδωεϞσϧ • MVC, MVVM,

    MVP, DDD…ͰͷϞσϧ • αʔόʔαΠυͷϞσϧɺΫϥΠΞϯταΠυͷϞσϧ • ActiveRecord, DAO, DTO…
  2. ࢥߟͱͯ͠ͷϞσϧ(1/2) • Ϟσϧ͸ҙਤΛઆ໌͢Δଘࡏ • ஌ࣝΛཁ໿ͨ͠γϯϓϧͰ෼͔Γ΍͍͢આ໌ • ෳࡶͳ΋ͷ͝ͱΛγϯϓϧʹදݱͨ͠΋ͷ(ܕ͕ Ϟσϧ) • ϞσϧΛ࡞Δͱࢥߟ͢Δͷ྆ྠΛճ͍ͯ͘͠ͷ͕

    ϞσϧԽ • ཁૉɾࣄ৅ΛͲͷΑ͏ʹ෼ׂ͢Δ͔ɺؔ܎ੑ͔Β ந৅Խɾ۩ମԽΛߟ͑ͲͷΑ͏ʹόϥ͍͔ͯ͘͠ɺ όϥͨ͠ཁૉ͔ΒͲͷΑ͏ʹશମΛద੾ʹઆ໌Ͱ ͖ΔΑ͏ʹͳΔ͔ͷԟ෮ӡಈ(ࢥߟ)͕ͦ͜Ϟσϧ ࡞Γͷຊ࣭
  3. OOͰͷϞσϧ(1/2) • OOP͸ਓؒͷਫ਼ਆΛ֦ுͨ͠΋ͷ • OO͸ਓʑͱͦͷϝϯλϧϞσϧʹؔ͢Δ΋ͷͰ͋ΓɺϙϦϞϑΟζϜ ΍݁߹ɾڽूʹؔ͢Δ΋ͷͰ͸ͳ͍ • OOPʹΑͬͯιϑτ΢ΣΞΛ࡞੒͢Δͱ͍͏͜ͱ͸ɺݴ͍׵͑Ε͹Ϟ σϧΛ࡞੒͢Δ͜ͱ =

    ϞσϧΛద੾ʹ࡞੒Ͱ͖͍ͯͳ͍ͷ͸OOPͱݺ ͹ͳ͍ • “σʔλ”ͱ”ৼΔ෣͍”Λ࣋ͭଘࡏ • ΦϒδΣΫτ͸ޓ͍ʹϝοηʔδΛૹΓ߹͏͜ͱͰɺޓ͍ͷৼΔ෣͍ Λ࣮ߦ͢Δ(ϝοηʔδύογϯά)
  4. OOͱݱ࣮ੈք͸શવҧ͏ • ΦϒδΣΫτࢦ޲͸ݱ࣮ੈքΛͦͷ··ιϑτ΢ΣΞʹදݱ͢Δٕज़ͱ͍͏આ໌͸ؒ ҧ͍ 1. ݱ࣮ੈք͸ઌʹ۩ମతͳ΋ͷ͕͋ΓɺͦΕΛ༷ʑͳج४Ͱ෼ྨ͢Δ 2. ݱ࣮ੈք͸࣌ؒ࣠΍ίϯςΩετͰRole͕มԽ͍ͯ͘͠(OOPͰ͸1छྨͷΫϥ ε͔ΒΠϯελϯε͕࡞ΒΕΔ) 3.

    ݱ࣮ੈք͸ݸਓݸਓ͕ҙࢥΛ࣋ͬͯࣗ༝ʹಈ͘ɺOOPͷΠϯελϯε͸֎෦͔ Βͷࢦ͕ࣔͳ͍ݶΓࣗ෼͔Βಈ͘ࣄ͸ͳ͍ɺ͋Β͔͡ΊܾΊΒΕͨࣄΛͦͷ௨ Γʹ͔࣮͠ߦͰ͖ͳ͍ • ݱ࣮ੈքͷҰ෦Λݞ୅ΘΓ͢Δ͚ͩͰɺݱ࣮ੈքͦͷ΋ͷΛදݱ͢ΔΘ͚Ͱ͸ͳ͍ • ݱ࣮ΛදݱͰ͖Δͷ͸͋͘·Ͱ΋੩తϞσϧ(֓೦Ϟσϧ)·ͰͰ͋ΓɺಈతϞσϧ(෺ ཧϞσϧ)͸ݱ࣮ͱͷྨࣅੑ͸͋·Γͳ͍
  5. OOͰͷϞσϧ(2/2) • OO͸ɺ෼ੳʹجͮ͘Ϟσϧ(ʹղऍ)هड़ͷҰൠతख๏Λࢧԉ͢Δ • ର৅Λཧղ͢ΔͨΊʹɺཁૉΛ෼ղ • ߏ੒ཁૉ͕ΦϒδΣΫτ • ߏ੒ཁૉؒͷؔ܎͸ΦϒδΣΫτͷؔ࿈ •

    ֊૚ཧղ͸ΧϓηϧԽͱͯ͠ද͢ • ಈతͳৼΔ෣͍͸implementationʹԡ͠෇͚Δ(ղܾ͸Ͱ͖͍ͯͳ͍?) • OOͷϞσϧ͸ݱ࣮ੈքͷ֓೦(੩త)Λදݱͨ͠ଘࡏ
  6. MVC͔ΒݟͨϞσϧ • MVCͩΖ͏͕ɺMVP, MVVM, MVI…ͩΖ͏͕ϨΠϠʔΛ෼཭ͨ͠ΞʔΩςΫ νϟͷ໨తͷҰͭ͸ϞσϧΛִ཭͢Δͱ͍͏ࣄ • M͸ΞϓϦέʔγϣϯͷதͰͷϏδωεϩδοΫΛ୲౰͢Δɺ͍Θ͹ΞϓϦ έʔγϣϯͷຊମ෦෼ɺຊ࣭ʹ౰ͨΔ •

    M͸ೖग़ྗ΍දࣔͱ͍ͬͨॲཧΛߦ͏͜ͱ͸Ͱ͖ͳ͍ • M͸ٕज़ʹґଘ͠ͳ͍Plainͳଘࡏ(POJO, PORO)Ͱ͋Δ΂͖ • ActiveRecord ͸͡ΊORMͦΕࣗମ͸͋͘·Ͱ΋MΛࢧ͑Δ΋ͷͰ͋ͬͯ MͰ͸ͳ͍ • ۃ࿦ɺGUI/CUI/WebAppͰ΋มΘΒͳ͍ॲཧ͕͋ΔͳΒͦΕ͸Mͷ࢓ࣄ
  7. DDDͱ͸ • Domain-Driven Design • υϝΠϯϞσϧΛத৺ʹߟ͑Δઃܭࢥ૝ • DDD͸ݴ༿Λେ੾ʹ͢Δઃܭࢥ૝ • XP(ΠϯΫϦϝϯλϧͳઃܭ)

    + OO(ΦϒδΣΫτࢦ޲) • OOͷຊҙΛܧঝͨ͠··࣮ફͨ͠ͷ͕DDD • ܾͯ͠৽͍͠΋ͷͰ͸ͳ͍ɺۜͷ஄ؙͰ΋ͳ͍ • ίϛϡχέʔγϣϯίετ͕ߴ͍(ਓ͕ଟ͍)ͱ͜͸DDD͕අ༻ରޮՌ͕ߴ ͍͔΋
  8. υϝΠϯϞσϧͱ͸ • υϝΠϯϞσϧ͸ಛఆͷਤͰ͸ͳ͘ɺਤ͕఻͑Α͏ͱ͢Δ ߟ͑ํͰ͋Δ • ͦͷ஌͕ࣝݫີʹߏ੒͞Εɺબͼൈ͔Εͯந৅Խ͞Ε ͨ΋ͷ • Ϟσϧͱ͸ɺϓϩδΣΫτʹܞΘΔਓʑͷ಄ͷதͰߏங͞ Εͨ֓೦ͷू·ΓͰ͋ΓɺυϝΠϯʹ͍ͭͯͷಎ࡯Λ൓ө

    ͨ͠ɺ༻ޠͱ֓೦ͷؔ܎ੑ͔ΒͰ͖͍ͯΔ • Ϟσϧͱ͸બͼൈ͔Εγϯϓϧʹ͞Εɺҙਤతʹ૊Έཱͯ ΒΕͨ஌ࣝͷදݱܗࣜͰ͋Δɻద੾ͳϞσϧ͸৘ใͷ࣋ͭ ҙຯΛ໌Β͔ʹ͠ɺͦͷ৘ใΛ໰୊ʹूதͤ͞Δ • υϝΠϯϞσϧ͸໰୊ྖҬΛදͨ͠΋ͷ(υϝΠϯϞσϧ ͚ͩͰ͸ػೳཁٻΛຬͨ͢͜ͱ͕Ͱ͖ͳ͍) • υϝΠϯϞσϧ͸ར༻ऀ(ϝϯλϧ)ͷؔ৺ຖͷ໛ܕ
  9. ڥք͚ͮΕͨίϯςΩετ(1/2) • υϝΠϯ͸໰୊ۭؒͱղܾۭؒΛ͍࣋ͬͯΔ • ໰୊ۭؒ: ղܾ͢΂͖Ϗδωεઓ্ུͷ՝୊Λු͖ ூΓʹ͢Δ΋ͷ • ղܾۭؒ: ιϑτ΢ΣΞΛͲͷΑ͏ʹ࣮૷ͯͦ͠ͷ

    ՝୊Λղܾ͢Δ͔ʹ஫໨͢Δ΋ͷ(ڥք෇͚ΒΕͨ ίϯςΩετ) • ڥք͚ͮΕͨίϯςΩετ͸໌ࣔతͳڥքͰ͋Γɺυϝ ΠϯϞσϧ͕Ͳ͜ʹଐ͢Δ͔Λද͢΋ͷ • ex. จ຺͕ந৅Խ͞Εͨ΋ͷ͕ه߸ɻจ຺͕ڞ༗͞Εͯ ͍ͳ͍ͱҙຯΛղऍͰ͖ͳ͍ɻͦͷจ຺͕ͦ͜ڥք෇͚ ΕͨίϯςΩετ
  10. See also(links) • Ϟσϧͱ͸Կ͔ʁ http://dse.ssi.ist.hokudai.ac.jp/~onosato/lectures/DSE19/H19-Model.pdf • ΦϒδΣΫτࢦ޲ͱ10೥ઓͬͯΘ͔ͬͨ͜ͱ http://qiita.com/tutinoco/items/ 6952b01e5fc38914ec4e •

    ϨΠϠʔઃܭͱ͔ɺΦϒδΣΫτࢦ޲ͱ͔ɺDDDͱ͔ɺͦͷล http://mattun.hatenablog.com/ entry/2014/07/19/135320 • OO͸੩తߏ଄Λɺؔ਺ܕ͸ಈతৼΔ෣͍ΛϞσϧԽ͢Δͷʹ༗༻ͩͱ͍͏࿩ɹhttp:// tanakakoichi9230.hatenablog.com/entry/3741984190 • ʮMVCͷצҧ͍ʯʹ͍ͭͯɺ΋͏Ұ౓ߟ͑ͯΈΔ http://at-grandpa.hatenablog.jp/entry/2013/11/ 01/072636 • FiNC DDDୈҰճษڧձ http://www.slideshare.net/hirokishigemura9/ruby-ddd • ϞσϦϯά΋͠ͳ͍ͰXPͱ͸Կࣄͩ http://www.slideshare.net/iwaoRd/xp-20150912
  11. See also(links) • ϦΞΫςΟϒDDD https://speakerdeck.com/j5ik2o/riakuteibuddd?slide=23 • GANMA!ͰDDDΛ΍ͬͯΈ͔ͯΒ1೥͘Β͍ܦͬͨ http://www.slideshare.net/ yasuyukisugitani/septeni-scala3 •

    DCIΞʔΩςΫνϟʹ͍ͭͯޠͬͯΈΔΑ http://uehaj.hatenablog.com/entry/20100528/ 1275011951 • ͦͷޙͷJoe ArmstrongͷΦϒδΣΫτࢦ޲ʹର͢Δݟղ http://qiita.com/lambda-knight/ items/a33feffe947a958a2d3a • DCIΞʔΩςΫνϟͷཧ࿦ͱGrailsʹΑΔ࣮૷ http://d.hatena.ne.jp/digitalsoul/20101110/ 1289315452)