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

Fat Modelに対処する
6つのリファクタリングパターン

Fat Modelに対処する
6つのリファクタリングパターン

2019/09/15 大阪Ruby会議02 登壇資料 https://regional.rubykaigi.org/osaka02/
Fat Modelに対処する
6つのリファクタリングパターン

Kaoru Hotate

September 15, 2019
Tweet

More Decks by Kaoru Hotate

Other Decks in Programming

Transcript

  1. DMBTT"SUJDMF"QQMJDBUJPO3FDPSE CFMPOHT@UPDBUFHPSZ TDPQFGJMUFSFE@CZ@DBUFHPSZ  DBUFHPSZ \ JGDBUFHPSZ KPJOT DBUFHPSZ NFSHF

    $BUFHPSZXIFSF OBNFDBUFHPSZ  FOE ^ FOE ϦϑΝΫλϦϯάલͷίʔυྫʢهࣄΫϥεʣ $PMMFDUPS0CKFDU
  2. DMBTT"SUJDMFT$PMMFDUPS EFGJOJUJBMJ[F QBSBNT  !QBSBNTQBSBNT FOE  EFGDBMM BSUJDMFT"SUJDMFQVCMJTIFE BSUJDMFTGJMUFSJOHDBMM

    BSUJDMFT  BSUJDMFTPSEFSJOHDBMM BSUJDMFT  BSUJDMFTQBHF QBSBNT<QBHF> QFS   FOE "SUJDMFT$POUSPMMFS"SUJDMFT$PMMFDUPS"SUJDMF'JMUFSJOH $PMMFDUPS0CKFDU QSJWBUF  BUUS@SFBEFSQBSBNT  EFGGJMUFSJOH "SUJDMF'JMUFSJOHOFX  QBSBNTQFSNJU DBUFHPSZ    FOE
  3. DMBTT"SUJDMF'JMUFSJOH JODMVEF"DUJWF.PEFM.PEFM BUUS@BDDFTTPSDBUFHPSZ WBMJEBUFTDBUFHPSZ TPNFUIJOH@SVMF  EFGDBMM SFTPVSDFT  SFUVSOSFTPVSDFTJGDBUFHPSZCMBOL

      KPJOT DBUFHPSZ NFSHF $BUFHPSZXIFSF OBNFDBUFHPSZ  FOE FOE "SUJDMFT$POUSPMMFS"SUJDMFT$PMMFDUPS"SUJDMF'JMUFSJOH $PMMFDUPS0CKFDU
  4. DMBTT"DD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࡞੒ͨ͠৔߹ɺطಡऀ؅ཧςʔϒϧʹ*/4&35͢Δ BSUJDMFWJFXFSTDSFBUF VTFSBSUJDMFPXOFS JGCZVTFS  FOE FOE ϦϑΝΫλϦϯάલͷίʔυྫ ΦϒδΣΫτΛ૿΍ͯ͠෼ذΛݮΒ͢
  13. DMBTT"SUJDMF$SFBUPS FOVNCZ<VTFS BENJO>  EFGTBWF QBSBNT CZCZ  BSUJDMF"SUJDMFOFX QBSBNT

     BSUJDMFTBWF Ϣʔβʔ͕࡞੒ͨ͠৔߹ɺطಡऀ؅ཧςʔϒϧʹ*/4&35͢Δ BSUJDMFWJFXFSTDSFBUF VTFSBSUJDMFPXOFS JGCZVTFS  FOE FOE ϦϑΝΫλϦϯάલͷίʔυྫ ΦϒδΣΫτΛ૿΍ͯ͠෼ذΛݮΒ͢ FOVNͷΞΠςϜ਺͚ͩ ΫϥεΛ࡞Δ
  14. w 1BUUFSOTUP3FGBDUPS'BU"DUJWF3FDPSE.PEFMT IUUQTDPEFDMJNBUFDPNCMPHXBZTUPEFDPNQPTFGBUBDUJWFSFDPSE NPEFMT w 3BJMTͷϑΝοτϞσϧ໰୊ʹରॲ͢ΔલʹಡΜͰ΄͍͠هࣄ IUUQTRJJUBDPNLMSJVUTBJUFNTEGDDBG w 3BJMTͰ΍ͬͯ͠·͍͕ͪͳอकੑΛԼ͛ͯ͠·͏ίʔυͱͦͷղܾࡦ IUUQTRJJUBDPNTIVOIJLJUBJUFNTGECEDFDGD

    w J04ΞϓϦઃܭύλʔϯೖ໳ IUUQTQFBLTDDCPPLTJ04@BSDIJUFDUVSF w 4BOEJ.FU[ΦϒδΣΫτࢦ޲ઃܭ࣮ફΨΠυd3VCZͰΘ͔ΔਐԽ͚ͭͮ͠Δॊೈ ͳΞϓϦέʔγϣϯͷҭͯํ w 3PCFSU$.BSUJO$MFBO"SDIJUFDUVSFୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ ࢀߟจݙ